1

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();

パスワード付与タイプを許可するためのグローバル設定はありますか?

4

2 に答える 2

2

次のように、コンマ区切りの文字列値ではなく、Variable Argumentsを使用する必要があります。

.authorizedGrantTypes("authorization_code, refresh_token, password")

それを次のように置き換えます。

.authorizedGrantTypes("authorization_code", "refresh_token", "password")
于 2016-03-06T17:14:03.823 に答える