I use Auth0 API. The whole application is on a single Tomcat server, HTTPS connector. If the WebFilter checking for authentication finds the auth tokens, it does not call LoginServlet but normally continues to the destination servlet.
There are two cases when /authorize on Auth0's server is called:
A link to some servlet S in a static web page, intercepted by a WebFilter. WebFilter then calls (if no auth tokens found) LoginServlet which successfully authenticates using Auth0, never a problem here.
JS' fetch() to a servlet X, intercepted by the same WebFilter as above. WebFilter then calls (again, if no auth tokens found) exactly the same LoginServlet which calls exactly the same /authorize URL. This time it always fails with "No 'Access-Control-Allow-Origin' header".
Yet, if WebFilter finds the auth tokens and forwards normally to the servlet X, this one in turn has no problems calling Auth0 /userinfo.
The "No 'Access-Control-Allow-Origin' header" message specifies Origin, which is correct, the same in both cases, just the app's domain, and exists in Auth0 Application settings Allowed Web Origins and Allowed origins (CORS).
What is the source of the problem? How to authenticate an user, if his first interaction with the application is via JS? For example, the app' page is open, the session times outs and then the user presses a key which causes JS make call a servlet which requires an authentication.
Do not known if it has anything to do, but I run Tomcat on my local machine, so it is also localhost for Chrome.
Also, just tested: exactly the same servlet called via URL in browser's address bar or via a clicked link logs in ok, but called via fetch() causes the CORS error in question.