title: Spring Security oauth2 redirects to login
body: <p>Attempting to integrate Okta into my Spring Web MVC application. Since I'm not using Spring Boot, I'm forced to follow the example in this link at the very bottom: <a href="https://github.com/spring-projects/spring-security/tree/master/samples/boot/oauth2login" rel="nofollow noreferrer">https://github.com/spring-projects/spring-security/tree/master/samples/boot/oauth2login</a></p>
  
  <p>So this is what I have:    </p>
  
  <pre><code>@EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Value("#{environment['okta.client-id']}")
      private String clientId;
      @Value("#{environment['okta.client-secret']}")
      private String clientSecret;
      @Value("#{environment['okta.redirect-uri']}")
      private String redirectUri;
      @Value("#{environment['okta.authorization-uri']}")
      private String authorizationUri;
      @Value("#{environment['okta.token-uri']}")
      private String tokenUri;
      @Value("#{environment['okta.user-info-uri']}")
      private String userInfoUri;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
                  .authorizeRequests()
                  .anyRequest().authenticated()
                  .and()
                  .oauth2Login()
                  .clients(clientRegistrationRepository())
                  .userInfoEndpoint()
                  .userInfoTypeConverter(
                          new UserInfoConverter(),
                          new URI(userInfoUri));
      }
  
      @Bean
      public ClientRegistrationRepository clientRegistrationRepository() {
          List&lt;ClientRegistration&gt; clientRegistrations = Collections.singletonList(clientRegistration());
  
          return new InMemoryClientRegistrationRepository(clientRegistrations);
      }
  
      private ClientRegistration clientRegistration() {
  
          return new ClientRegistration.Builder(clientId)
                  .clientSecret(clientSecret)
                  .clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
                  .authorizedGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
                  .redirectUri(redirectUri)
                  .scopes("openid", "email", "profile")
                  .authorizationUri(authorizationUri)
                  .tokenUri(tokenUri)
                  .userInfoUri(userInfoUri)
                  .clientName("Okta")
                  .clientAlias("okta")
                  .build();
      }
  }
  </code></pre>
  
  <p>However, as soon as I log in sucessfully with Okta, it redirects me back to the login page: (<a href="http://localhost:8081/login" rel="nofollow noreferrer">http://localhost:8081/login</a>). Clicking the Okta button to login again also redirects me to the same page.</p>
  
  <p>Any suggestions would be helpful.</p>