Spring OAuth2禁用TokenEndpoint的HTTP Basic Auth

Jak*_*iva 3 spring oauth spring-security spring-security-oauth2 spring-oauth2

我从Spring OAuth2开始.到目前为止,我已经使用配置保护了我的应用程序.但我有一个问题,我的客户端不支持HTTP基本授权.

有没有办法如何为/ oauth/token端点禁用HTTP Basic Auth?我想在JSON正文或请求标头中发送client_id和client_secret.

curl例子我想工作:

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"
Run Code Online (Sandbox Code Playgroud)

要么

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"
Run Code Online (Sandbox Code Playgroud)

Jak*_*iva 14

我终于搞清楚了.如何禁用HTTP Basich Auth的方法是为客户端启用表单身份验证.只需将这些行添加到您的配置中.

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

现在您将能够向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"
Run Code Online (Sandbox Code Playgroud)

但仍然存在ContentType application/json问题.有人有解决方案吗?