2017-03-29 1 views
2

Demande d'aide sur une demande BadCredentialsException de Spring Boot OAuth2 lorsque, après l'authentification et l'approbation de l'utilisateur, mon application client Oauth2 demande un jeton du point de terminaison de jeton du serveur OAuth2 AuthServer.Demande de jeton Spring Boot Oauth2 - Informations d'identification incorrectes du client BasicAuthenticationFilter

Les applications Spring Boot OAuth2 sont basés hors de la désormais célèbre Dave Syer Spring Boot/oauth2 UI Client/oauth2 authserver/JWT exemple https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2

Ceci est dans le débuggage Apps Client:

DEBUG org.springframework.web.client.RestTemplate - Created POST request for "authserver/uaa/oauth/token" 
DEBUG org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider - Encoding and sending form: {grant_type=[authorization_code], code=[xxxxx], redirect_uri=[oauthclientapp/login]} 
DEBUG org.springframework.web.client.RestTemplate - POST request for "authserver/uaa/oauth/token" resulted in 200 (null) 
DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token 

Ceci est le débogage du authserver:

DEBUG org.springframework.security.web.FilterChainProxy - /oauth/token at position 9 of 15 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
DEBUG org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Basic Authentication Authorization header found for user 'clientID' 
DEBUG org.springframework.security.authentication.ProviderManager - Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider 
DEBUG org.springframework.security.authentication.dao.DaoAuthenticationProvider - User 'clientID' not found 
DEBUG org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials 

l'application client oauth2 est tout comme celui dans l'exemple, pas de personnalisation dans la pr demande de jeton OSCESS, juste ce que @ EnableOAuth2Sso nous donne. La configuration de ClientDetails sur l'AuthServer est aussi juste comme l'exemple, exemple ci-dessous, donc rien de spécial.

Toutes les suggestions pour mieux résoudre ce problème sont très appréciées. Merci.

@Override 
     public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
      clients.inMemory() 
        .withClient("clientID") 
        .secret("acmesecret") 
        .authorizedGrantTypes("authorization_code", "refresh_token", 
          "password").scopes("openid"); 
     } 

Répondre

0

J'ai eu la même erreur avec votre configuration lors de l'envoi demande POST/oauth/point final jeton comme ceci:

curl localhost:8080/oauth/token -d grant_type=authorization_code -d client_id=acme -d redirect_uri=http://localhost:4200/redirectUrl -d code=5chf5f 

Mon intention était d'utiliser les flux de code d'autorisation et je ne voulais pas fournir le paramètre de client_secret qui a causé l'erreur

-d client_sercret=acmesecret 

Si votre situation est la même que vous pouvez ajouter un autre client sans secret flux de code d'autorisation:

@Override 
public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients.inMemory() 
       .withClient("clientWithSecret") 
       .secret("acmesecret") 
       .authorizedGrantTypes("password") 
       .scopes("openid") 
       .and() 
       .withClient("clientNoSecret") 
       .authorizedGrantTypes("authorization_code", "refresh_token") 
       .scopes("openid"); 
    }