spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

Support for defaultSuccessUrl, successHandler, failureUrl and failureHandler in case of oauth2Client similarly to oauth2Login

Open mucsi96 opened this issue 3 years ago • 0 comments

Expected Behavior

It would be great to have similar capabilities in oauth2Client as in oauth2Login to provide defaultSuccessUrl. In case of SPA this could be set to SPA index page.

Current Behavior

Currently in case of OAuth2 login it's very handy to provide defaultSuccessUrl for example if the application is an SPA. Unfortunately this is not possible with OAuth2 client. It doesn't support any callbacks (handlers) or url to redirect to after successful authorization. It's limited to redirecting back to previous request in request cache. But in case of SPA this might be empty which will result in redirecting to OAuth2 redirect url. https://github.com/spring-projects/spring-security/blob/main/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java#L244

Context

I have an Spring Boot REST API with Angular SPA client. I planned to have no non-REST endpoints in controllers. But looks like I have to create at least 1 non-REST endpoint. Something like "/login" just to make sure I will have a Spring url to come back to after successful authentication. This endpoint would simply redirect back to SPA index page. But this seems to be more like a workaround.

Application repository: https://github.com/mucsi96/training-log-pro

mucsi96 avatar Aug 10 '22 14:08 mucsi96