Spring Boot OAuth2 ERR_TOO_MANY_REDIRECTS Solved


Having Issues Integrating OAuth2 with your Java Spring Boot Project.

Let us see what is the issue that occurs when redirecting back to your application after a successful OAuth2 Authentication -

Spring Boot OAuth2 ERR_TOO_MANY_REDIRECTS Solved


The reason this error occurs is because when the redirect URL is set under the authorization service it is not defined as a allowed or permitted URL inside the Spring Boot Application.

The allowed or permitted URL is that URL that can be accessed without authentication also.

When the authorization service in Application redirects the Application to a non-permitted URL, it will again redirect back to the authorization service for doing further authentication. Due to this, the Application process enters into a loop that doesn't end, which further leads to ERR_TOO_MANY_REDIRECTS problem.

In order to allow the Spring Boot Application, access to the callback URL, you will have to extend WebSecurityConfigurerAdapter and override the security configuration code as follows:

@Configuration @EnableOAuth2Sso public class MySecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .antMatcher("/**") .authorizeRequests() .antMatchers("/", "/login**","/callback/", "/webjars/**", "/error**") .permitAll() .anyRequest() .authenticated(); } }

In the above code, we make "/callback" our redirect URL, so we allow or permit access to it using permitAll() function but we still secure the access for other URLs.

Solution Worked 7 UpvotesUpvote


Solution Didn't Worked 1 DownvotesDownvote


Play 2048 Game Online

Search Tags