0

私は認証サーバー(http://localhost:8082)、リソースサーバーと暗黙のクライアント(http://localhost:8080)プロジェクトを持っています。クライアントが認証(トークン)を要求すると、認証サーバはログイン画面を表示しますが、成功したログイン後にはhttp://localhost:8082/authorize?client_id= ...の代わりにGET http://localhost:8082/にリダイレクトされます(クライアントが要求したとおり)Spring OAuth2暗黙のフロー - 認証サーバーがPOST/oauth/authorizeリクエストを処理していない

暗黙クライアント:

.s.o.c.t.g.i.ImplicitAccessTokenProvider : Retrieving token from http://localhost:8082/oauth/authorize 
o.s.web.client.RestTemplate    : Created POST request for "http://localhost:8082/oauth/authorize" 
.s.o.c.t.g.i.ImplicitAccessTokenProvider : Encoding and sending form: {response_type=[token], client_id=[themostuntrustedclientid], scope=[read_users write_users], redirect_uri=[http://localhost:8080/api/accessTokenExtractor]} 
o.s.web.client.RestTemplate    : POST request for "http://localhost:8082/oauth/authorize" resulted in 302 (null) 
o.s.s.web.DefaultRedirectStrategy  : Redirecting to 'http://localhost:8082/login?client_id=themostuntrustedclientid&response_type=token&redirect_uri=http://localhost:8080/api/accessTokenExtractor' 

認証サーバ:

01私は、このログを見ています

暗黙のクライアントがGETするのではなく、/ oauth/authorizeのためにPOSTingしていますが、authserverはPOST要求を格納しません。認証サーバは、リダイレクト302を返し、暗黙のクライアントは、このURLにブラウザをリダイレクトします。それはhttp://localhost:8082/ので、それがどんな/ OAuthの/処理しません示してhttp://localhost:8082/login?client_id=themostuntrustedclientid&response_type=token&redirect_uri=http://localhost:8080/api/accessTokenExtractor

ログインに成功した後、認証サーバは、ターゲットURLを持っていません権限を要求する...問題はどこですか?

認証サーバーCONFIG:

@Configuration 
class OAuth2Config extends AuthorizationServerConfigurerAdapter{ 

    @Autowired 
    private AuthenticationManager authenticationManager 

    @Bean 
    public TokenStore tokenStore() { 
     return new InMemoryTokenStore(); 
    } 

    @Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients.inMemory() 
      .withClient("themostuntrustedclientid") 
      .secret("themostuntrustedclientsecret") 
      .authorizedGrantTypes("implicit") 
      .authorities("ROLE_USER") 
      .scopes("read_users", "write_users") 
      .accessTokenValiditySeconds(60)  
    } 

    @Override 
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 
     endpoints.authenticationManager(this.authenticationManager); 
    } 

    @Override 
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { 
     //security.checkTokenAccess('hasRole("ROLE_RESOURCE_PROVIDER")') 
     security.checkTokenAccess('isAuthenticated()') 
    } 

} 

@Configuration 
@EnableWebSecurity 
class SecurityConfig extends WebSecurityConfigurerAdapter{ 

    @Autowired 
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { 
     auth.inMemoryAuthentication().withUser("jose").password("mypassword").roles('USER').and() 
            .withUser("themostuntrustedclientid").password("themostuntrustedclientsecret").roles('USER') 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
     .csrf() 
      // 
      //XXX Si se usa implicit descomentar 
      .ignoringAntMatchers("/oauth/authorize") 
      .and() 
     .authorizeRequests() 
      .anyRequest().authenticated() 
      .and() 
     //.httpBasic() 
     .formLogin() 
      .loginPage("/login").permitAll() 
    } 

} 

IMPLICITクライアントCONFIG:

@Configuration 
class OAuth2Config { 

    @Value('${oauth.authorize:http://localhost:8082/oauth/authorize}') 
    private String authorizeUrl 

    @Value('${oauth.token:http://localhost:8082/oauth/token}') 
    private String tokenUrl 

    @Autowired 
    private OAuth2ClientContext oauth2Context 

    @Bean 
    OAuth2ProtectedResourceDetails resource() { 
     ImplicitResourceDetails resource = new ImplicitResourceDetails() 
     resource.setAuthenticationScheme(AuthenticationScheme.header) 
     resource.setAccessTokenUri(authorizeUrl) 
     resource.setUserAuthorizationUri(authorizeUrl); 
     resource.setClientId("themostuntrustedclientid") 
     resource.setClientSecret("themostuntrustedclientsecret") 
     resource.setScope(['read_users', 'write_users']) 
     resource 
    } 

    @Bean 
    OAuth2RestTemplate restTemplate() { 
     OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource(), oauth2Context) 
     //restTemplate.setAuthenticator(new ApiConnectOAuth2RequestAuthenticator()) 
     restTemplate 
    } 

@Configuration 
class SecurityConfig extends WebSecurityConfigurerAdapter{ 

    @Autowired 
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { 
     auth.eraseCredentials(false) 
      .inMemoryAuthentication().withUser("jose").password("mypassword").roles('USER') 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
     .csrf() 
      .ignoringAntMatchers("/accessTokenExtractor") 
     .and() 
     .authorizeRequests() 
     .anyRequest().hasRole('USER') 
     .and() 
     .formLogin() 
      .loginPage("/login").permitAll() 
    } 

} 

答えて

0

問題は、認証サーバのSecurityConfigにありました。暗黙のクライアントは、client_idおよびclient_secretを使用して基本認証ヘッダーを自動的に送信します。マイ認証サーバーは、基本認証の代わりにフォームログインを使用するように構成されていました。私はそれを変更し、今は期待どおりに動作します:

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
    .csrf() 
     // 
     //XXX Si se usa implicit descomentar 
     .ignoringAntMatchers("/oauth/authorize") 
     .and() 
    .authorizeRequests() 
     .anyRequest().authenticated() 
     .and() 
    .httpBasic() 
関連する問題