2017-03-22 47 views
0

當我嘗試訪問/的OAuth /令牌我得到錯誤:使用請求ID號сlient

o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: NoSuchClientException, No client with requested id: username

我得到了它在接下來的步驟:

  1. 我努力使請求的OAuth /授權,並得到彈出輸入憑據。
  2. 輸入,並得到錯誤「Unsupportted RESPONSE_TYPE」
  3. 然後我試圖讓通過OAuth /令牌決策請求令牌

curl -u clientsecret:12345 -X POST http://localhost:8080/oauth/token -H "Accept:application/json" -d "username=user&password=password&grant_type=password"

然後得到這個錯誤與NoSuchClientException。爲什麼它將用戶名設置爲clientId? 這是我的代碼:

@Configuration 
public class OAuth2ServerConfig { 

@Configuration 
@EnableResourceServer 
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 

    @Inject 
    private Http401UnauthorizedEntryPoint authenticationEntryPoint; 

    @Inject 
    private AjaxLogoutSuccessHandler ajaxLogoutSuccessHandler; 

    @Override 
    public void configure(HttpSecurity http) throws Exception { 
     http 
       .exceptionHandling() 
       .authenticationEntryPoint(authenticationEntryPoint) 
       .and() 
       .logout() 
       .logoutUrl("/logout") 
       .logoutSuccessHandler(ajaxLogoutSuccessHandler) 
       .and() 
       .csrf() 
       .requireCsrfProtectionMatcher(new AntPathRequestMatcher("oauth/token")) 
       .disable() 
       .headers() 
       .frameOptions().disable() 
       .and() 
       .sessionManagement() 
       .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 
       .and() 
       .authorizeRequests() 
       .antMatchers("/admin").hasAnyAuthority("ADMIN"); 
    } 
} 

@Configuration 
@EnableAuthorizationServer 
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 

    private static final String CLIENTID = "app"; 
    private static final String PROP_SECRET = "secret"; 
    private static final Integer TOKEN_VALIDITY_SECONDS = -1; 
    @Inject 
    private UserDetailsService userDetailsService; 
    @Inject 
    private OAuth2AccessTokenRepository oAuth2AccessTokenRepository; 

    @Inject 
    private OAuth2RefreshTokenRepository oAuth2RefreshTokenRepository; 

    @Bean 
    public TokenStore tokenStore() { 
     return new MongoDBTokenStore(oAuth2AccessTokenRepository, oAuth2RefreshTokenRepository); 
    } 

    @Inject 
    @Qualifier("authenticationManagerBean") 
    private AuthenticationManager authenticationManager; 

    @Override 
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) 
      throws Exception { 

     endpoints 
       .tokenStore(tokenStore()) 
       .authenticationManager(authenticationManager).userDetailsService(userDetailsService); 
    } 

    @Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients 
       .inMemory() 
       .withClient(CLIENTID) 
       .authorizedGrantTypes("authorization_code","refresh_token","password") 
       .authorities("USER", "ADMIN") 
       .secret(PROP_SECRET) 
       .accessTokenValiditySeconds(TOKEN_VALIDITY_SECONDS); 
    } 
} 
} 

回答

0

像這樣創建

curl app:[email protected]:8080/oauth/token -d grant_type=password -d client_id=app -d username=user -d password=password 
請求