4

私はSpring OAuth2から始めています。これまでのところ、構成でアプリを保護できました。しかし、問題があります。私のクライアントは HTTP Basic Authorization をサポートしていません。

/oauth/token エンドポイントの HTTP 基本認証を無効にする方法はありますか? JSON 本文または要求ヘッダーで client_id と client_secret を送信したいと考えています。

私が働きたいカールの例:

curl -X POST -H "Content-Type: application/json" -d '{
"username": "user",
"password": "pass",
"grant_type": "password",
"client_id": "test-client-id",
"client_secret": "test-client-secret"
}' "http://localhost:9999/api/oauth/token"

また

curl -X POST -H "Content-Type: application/json" -H "X-Client-ID: test-client-id" -H "X-Client-Secret: test-client-secret" -d '{
"username": "user",
"password": "pass",
"grant_type": "password"
}' "http://localhost:9999/api/oauth/token"
4

1 に答える 1

19

私はついにそれを理解します。HTTP 基本認証を無効にする方法は、クライアントのフォーム認証を有効にすることです。これらの行を構成に追加するだけです。

@Configuration
@EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
  @Override
  public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
    oauthServer.allowFormAuthenticationForClients();
  }
}

これで、次のように TokenEndpoint に成功したリクエストを送信できるようになります。

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'username=user_username&password=user_password&grant_type=password&client_id=your_trusted_client_id&client_secret=your_trusted_client_secret' "http://localhost:8080/oauth/token"

しかし、ContentType アプリケーション/json の問題がまだ残っています。誰にもこれに対する解決策がありますか?

于 2016-07-03T20:05:49.903 に答える