Changing BaseURI of OAuth2AuthorizationRequestRedirectFilter not Redirecting Properly

Viewed 197

I'm trying to get the baseUri of the OAuth2AuthorizationRequestRedirectFilter to redirect properly with a github-specific oauth chain but I can't seem to figure it out. My setup of the WebSecurityConfigurerAdapter has the ClientRegistrationRepository set and I'm using the following to set the base-uri:

.authorizationEndpoint()
.baseUri(GitHubRequestPaths.GITHUB_OAUTH_REDIRECT)
//Note the above is defined as:
//String GITHUB_OAUTH_REDIRECT = "/github/oauth2/authorization"

But Spring seems to be complaining that it can't match the authorization endpoint which I believe is making it so it doesn't correctly redirect to the github login for the OAuth2LoginAuthenticationFilter. I'm seeing the following in the debug which is what is leading me to that idea:

2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.security.web.FilterChainProxy        : /github/oauth2/authorization at position 5 of 12 in additional filter chain; firing Filter: 'OAuth2AuthorizationRequestRedirectFilter'
2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/github/oauth2/authorization'; against '/github/oauth2/authorization/{registrationId}'
2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.security.web.FilterChainProxy        : /github/login at position 6 of 12 in additional filter chain; firing Filter: 'OAuth2LoginAuthenticationFilter'
2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/github/login'; against '/login/oauth2/code/*'
2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.security.web.FilterChainProxy        : /github/login at position 7 of 12 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2021-12-07 10:20:24.015 DEBUG 11283 --- [nio-8091-exec-2] o.s.s.w.s.HttpSessionRequestCache        : saved request doesn't match

The way the web page is set up is that it gathers the login from a base directory call which returns the GitHub login as what I've set the authorization login call to be (/github/oauth2/authorization). I've tried manually setting the registration id (/github/oauth2/authorization/GitHub) but Spring just returns a similar error of looking for a match to /github/oauth2/authorization/GitHub/{registrationId}. It seems to try to match to baseUri + /{registrationId}, can I edit this behavior?

1 Answers

I was able to get around this by creating my own OAuth2AuthorizationRequestResolver which almost exactly mirrored DefaultOAuth2AuthorizationRequestResolver but with the registration id's hardcoded.

Related