title: Spring Oauth2 redirect uri doesn't change
body: <p>I'm working on OAuth2 Authorization in Spring and try to implement <code>authorization code</code> grant flow. Now I have two applications. Client side and authorization server side. When I open secured <code>/client/hello</code> it redirect me to oauth2 login page, after that a get <code>/oauth/authorize</code> link, but in <code>redirect_uri</code> value always is login page on client side and it even doesn't change manually in browser. How I can change it? If i change redirect uri to <code>/client/login</code> in auth server config it redirects and gives me authorization code, but invokes unauthorized error.</p>
  
  <p><strong>Client</strong></p>
  
  <p>Controller:</p>
  
  <pre><code>@RestController
  public class Controller {
      @GetMapping("/hello")
      public String hello() {
          return "Hello world!!";
      }
  
      @GetMapping("/public")
      public String publicPage() {
          return "This is public!!";
      }
  
      @GetMapping("/callback")
      public String login(@RequestParam("code") String code) {
          return code;
      }
  }
  </code></pre>
  
  <p>Client security config:</p>
  
  <pre><code>@Configuration
  @EnableOAuth2Sso
  public class ClientSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers("/error**", "/public**").permitAll()
                  .anyRequest().authenticated();
      }
  }
  
  </code></pre>
  
  <p>Client properties:</p>
  
  <pre><code>security.oauth2.client.client-id=007314
  security.oauth2.client.client-secret=MDA3MzE0
  security.oauth2.client.grant-type=password
  security.oauth2.client.scope=read
  security.oauth2.client.pre-established-redirect-uri=http://localhost:8081/client/public
  security.oauth2.client.access-token-uri=http://localhost:8082/auth/oauth/token
  security.oauth2.client.user-authorization-uri=http://localhost:8082/auth/oauth/authorize
  security.oauth2.client.authentication-scheme=form
  security.oauth2.resource.user-info-uri=http://localhost:8081/client/hello
  security.oauth2.resource.id=resource-server-rest-api
  
  server.port=8081
  server.servlet.context-path=/client
  </code></pre>
  
  <p><strong>Authorization Server</strong>
  Server config:</p>
  
  <pre><code>@Configuration
  @EnableAuthorizationServer
  public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {
  
  
      private final PasswordEncoder passwordEncoder;
      @Qualifier("authenticationManagerBean")
      private final AuthenticationManager authenticationManager;
  
      @Autowired
      public AuthorizationServer(PasswordEncoder passwordEncoder, AuthenticationManager authenticationManager) {
          this.passwordEncoder = passwordEncoder;
          this.authenticationManager =  authenticationManager;
      }
  
      @Override
      public void configure(AuthorizationServerSecurityConfigurer security) {
          security.tokenKeyAccess("permitAll()")
                  .checkTokenAccess("isAuthenticated()")
                  .passwordEncoder(passwordEncoder)
                  .allowFormAuthenticationForClients();
      }
  
      @Override
      public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
          clients.inMemory()
                  .withClient("007314")
                  .secret(passwordEncoder.encode("007314"))
                  .authorizedGrantTypes("authorization_code", "refresh_token")
                  .scopes("read")
                  .resourceIds("resource-server-rest-api")
                  .autoApprove(true)
                  .redirectUris("http://localhost:8081/client/hello");
      }
  
      @Bean
      public TokenStore tokenStore(){
          return new JwtTokenStore(defaultAccessTokenConverter());
      }
      @Bean
      public JwtAccessTokenConverter defaultAccessTokenConverter() {
          JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
          converter.setSigningKey("123");
          return converter;
      }
  
      @Override
      public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
          endpoints.tokenStore(tokenStore())
                  .accessTokenConverter(defaultAccessTokenConverter())
                  .authenticationManager(authenticationManager);
      }
  }
  </code></pre>
  
  <p>Server security config:</p>
  
  <pre><code>@EnableWebSecurity
  @Order(1)
  public class ServerSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      @Bean
      public AuthenticationManager authenticationManagerBean() throws Exception {
          return super.authenticationManagerBean();
      }
  
      @Bean
      public PasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication().passwordEncoder(passwordEncoder())
                  .withUser("qwerty")
                  .password(passwordEncoder().encode("12345"))
                  .roles("USER");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers("/error**", "/login**", "/oauth/authorize**").permitAll()
                  .anyRequest().authenticated()
                  .and()
                  .formLogin().permitAll();
      }
  }
  </code></pre>
  
  <p><strong>Resource Server</strong></p>
  
  <pre><code>@Configuration
  @EnableResourceServer
  public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
  
      private static final String RESOURCE_ID = "resource-server-rest-api";
      @Override
      public void configure(ResourceServerSecurityConfigurer resources) {
          resources.resourceId(RESOURCE_ID);
      }
      @Override
      public void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers(HttpMethod.GET, "/client/hello").access("#oauth2.hasScope('read')");
      }
  }
  </code></pre>
  
  <p>Server properties:</p>
  
  <pre><code>server.port=8082
  server.servlet.context-path=/auth
  </code></pre>