2016-03-06 618 views
0

在我的Java服務器應用程序,我在嘗試使用密碼補助流量進行身份驗證時出現以下錯誤:Spring OAuth2:如何使用java配置允許密碼授權類型?

TokenEndpoint - Handling error: InvalidClientException, Unauthorized grant type: password 

我也允許授予明確的用戶問題:

@Override 
public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
    clients.inMemory() 
      .withClient("officialclient") 
       .authorizedGrantTypes("authorization_code, refresh_token, password") 
       .authorities("ROLE_CLIENT") 
       .scopes("read", "write") 
       .resourceIds(RESOURCE_ID) 
       .secret("officialclientsecret") 
       .redirectUris("https://www.someurl.com/") 
} 

我我正在使用以下代碼來檢索訪問令牌:

ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails(); 
resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header); 
resourceDetails.setAccessTokenUri("http://localhost:8080/organizer/oauth/token"); 
resourceDetails.setScope(Arrays.asList("read", "write")); 
resourceDetails.setId("resource"); 
resourceDetails.setClientId("officialclient"); 
resourceDetails.setClientSecret("officialclientsecret"); 
resourceDetails.setUsername("Paul"); 
resourceDetails.setPassword("password"); 

OAuth2RestTemplate template = new OAuth2RestTemplate(resourceDetails, context); 
return template.getAccessToken().getValue(); 

是否有允許密碼授權類型的全局設置?

回答

1

您應該使用變參數,不以逗號分隔字符串值,像你一樣:

.authorizedGrantTypes("authorization_code", "refresh_token", "password") 

.authorizedGrantTypes("authorization_code, refresh_token, password") 

將其替換

相關問題