Search code examples
spring-securityspring-authorization-server

Spring Authorization Server: how to continue authorization after login


I am trying to integrate Authorization Server into my app with form login. I'm using my own login page. Samples suggest to use the following configuration:

public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http)
            throws Exception {
        OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
//...
        http
                // Redirect to the login page when not authenticated from the
                // authorization endpoint
                .exceptionHandling((exceptions) ->
                    exceptions
                         .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"));
//...
                )

Now when I try to authorize (/oauth2/authorize?...) I got redirection to my login page. If I logged in before I see OAuth consent page and able to submit consent. But 99% of times I see my /login page, able to log in and stuck here. How to continue to consent page there? Should I write my own logic for that?


Solution

  • Solved issue myself by removing custom .successHandler(...) from my custom form login configuration. Default SavedRequestAwareAuthenticationSuccessHandler correctly handle all redirects as expected.