-
Notifications
You must be signed in to change notification settings - Fork 6k
oauth2Login does not auto-redirect for XHR request #6812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@simpleway This seems like a reasonable improvement. Would you be interested in submitting a PR? |
@rwinch Sure, I can work on a PR.
Not ideal, since hardcoded OpenID Connect provider login page, but good enough to overwrite the default behavior. |
@simpleway This isn't an oauth-specific issue. If your application was using I personally feel that the ajax client should handle 401's on whether the session is expired or if calling without authentication credentials. |
@jgrandja I would recommend to separate API endpoints to use Bearer token with oauth2ResourceServer configuration. However, this will require UI component to hand over access token or JWT, which need additional development cycles. Although sharing the same
and abort the redirect request. |
I don't really understand this statement. Which API endpoints are you referring to? This does not seem related to the issue on hand?
This is not completely true. If an unauthenticated request comes in than the At this point, I would suggest that you put together a minimal sample so I can better understand what you are trying to do as it doesn't seem totally clear and I feel your use case is not how Authorization Code flow is meant to be used. Please see this post to understand what the expectation of a minimal sample is. Thank you. |
@simpleway We investigated this further and discovered a bug. I apologize for the confusion on my part as I didn't fully understand the actual problem you were having. When the application has one The fix is now in master so please give it a try and let me know how it goes. I'll have this back-patched to 5.1.x as well. |
This issue is related to #6638.
I use single OpenIDC IdP (google) from OAuth2Login Sample. Added a rest endpoint that use the same security configuration. When an ajax request to the rest endpoint with an expired JSESSIONID or no JESSIONID at all, the response is a redirect to google IdP. The redirect will be blocked by the browser since cross domain redirect is not allowed in CORS policy.
After tracing the code a little bit, and found the request matcher logic in
OAuth2LoginConfigurer
might contribute to this behavior:spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Line 450 in 5aacd0c
spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Lines 619 to 634 in 5aacd0c
The
defaultEntryPointMatcher
will filter out XMLHttpRequest. Should theentryPoints
be something likeThen the AJAX call to data will simply got 401 instead of a redirect, which the browser will block since it will be a cross domain redirect.
Originally posted by @simpleway in #6638 (comment)
The text was updated successfully, but these errors were encountered: