2016-03-06 126 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") 

将其替换

相关问题