SpringOAuth2から始めています。これまでのところ、この構成でアプリを保護しました。しかし、問題があります。私のクライアントはHTTP基本認証をサポートしていません。
/ oauth / tokenエンドポイントのHTTP基本認証を無効にする方法はありますか?client_idとclient_secretをJSON本文またはリクエストヘッダーで送信したいと思います。
私が働きたいカールの例:
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"
私はついにそれを理解しました。HTTP Basich Authを無効にする方法は、クライアントのフォーム認証を有効にすることです。それらの行を構成に追加するだけです。
@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 application / jsonの問題はまだ残っています。誰かがこれに対する解決策を持っていますか?
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加