-
Notifications
You must be signed in to change notification settings - Fork 6k
Webflux Oauth2 .oauth2Client() doesn't redirect back to the original request after authenticating in the auth server #6341
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
It seems the |
Thanks for the report and anyalysis @rozagerardo! Would you be interested in submitting a PR for this? |
Thanks for the quick response @rwinch |
Thanks @rozagerardo! Let us know if you run into any issues and we will do our best to help |
When we used the oauth2Client directive and requested an endpoint that required client authorization on the authorization server, the SPRING_SECURITY_SAVED_REQUEST was not persisted, and therefore after creating the authorized client we were redirected to the root page ("/"). Now we are storing the session attribute and getting redirected back to the original URI as expected. Note that the attribute is stored only when a ClientAuthorizationRequiredException is thrown in the chain, we dont want to store it as a response to the /oauth2/authorization/{registrationId} endpoint, since we would end up in an infinite loop Fixes spring-projectsgh-6341
Thanks for the support @rwinch it's been a nice first experience contributing to this project :) |
Thanks again for your contribution! If you are looking for more tasks to work on, you can find ideal tickets with the Help Wanted label. Of course if you find something else, please just let us know and we can help determine if it is something we are interested in contributions for. |
Summary
When configuring a WebFlux application as an OAuth2 Client using an authentication_code grant type and without implementing the OAuth2Login feature, the application redirects to the "/" path after authenticating in the Authentication Server instead of redirecting back to the original request
Actual Behavior
1-Calling an endpoint in an OAuth2 Client application (without using OAuth2 login) using Auth code Grant type
2- Authenticate in the Authorization Server
3- Get redirected to the /authorize/oauth2/code/[myclient] endpoint
4- Get redirected to the root ("/") URL
Expected Behavior
1-Calling an endpoint in an OAuth2 Client application (without using OAuth2 login) using Auth code Grant type
2- Authenticate in the Authorization Server
3- Get redirected to the /authorize/oauth2/code/[myclient] endpoint
4- Get redirected to the endpoint we called in the first place
Configuration
1- Set up an application with the following using the following ServerHttpSecurity configuration:
2- A client registration:
Note: In my case, I set up the Client registration using Spring Boot 2.x. The client is registered in a custom Authentication Provider that I configured using Spring Security Oauth, but the issue should be present for well-known providers as well.
3- Configure the WebClient:
4-And the endpoint that I'm using:
5- Now call the
/auth-code-oauth
endpoint. We get redirected to the Authentication login form, approve the required scopes, and after being redirected to the specified redirect-uri (/authorize/oauth2/code/myclient) the application retrieves the token, and we are redirected to the root ("/") url, instead of the endpoint that I actually called in the first place. If I make the call to the/auth-code-oauth
endpoint again afterwards, the retrieved response is the expected, since no authentication process is carried out at this point.Included a link to the sample by the end of the description
Version
Spring Boot 2.1.1.RELEASE
Spring Security: 5.1.2.RELEASE
Sample
https://github.com/rozagerardo/samples
The text was updated successfully, but these errors were encountered: