title: How do I modify spring boot security redirect on login to not redirect back to login?
body: <p>We have a spring boot application configured as an oauth2 client.  Occasionally, we have people where their browser sends a request like this to the application:</p>
  <p>https://app/login?code=XXX&amp;state=ZZZ</p>
  <p>The code and state were cached from a previous authentication attempt and are invalid right now.</p>
  <p>Spring security sees that this person is not authenticated, so it redirects them to /login which then does the whole oauth2 authentication but then after they are authenticated, spring security sends them back to /login?code=XXX&amp;state=ZZZ because that was their original request.  When that happens, it tries to validate the code and state but fails and sends them to an error page.  This is a problem when supporting the app because the user is authentcated.</p>
  <p>Is there a way to change the logic of the the storing of the initial request so that if it is /login we can replace that with /?  There might be other solutions we haven't thought of.  Any help would be appreciated.</p>
  <p>Our app is currently using Spring boot 2 but I've tried this with the latest version of Spring boot 3 and it is still an issue.  We have been unable to change the browser behavior so would like to solve this on the server if possible.</p>
  <p>Here is our configuration:</p>
  <pre><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
      http.antMatcher(&quot;/**&quot;)
              .authorizeRequests()
              .antMatchers(&quot;/info&quot;, &quot;/static/**&quot;).permitAll()
              .anyRequest().authenticated().and()
              .csrf();
  }
  </code></pre>