【发布时间】:2015-11-09 22:35:40
【问题描述】:
我的批次必须使用 OAuth2 和授权类型的客户端凭据连接到 Web 服务
代码如下:
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(accessTokenUri);
resource.setClientId(clientId);
resource.setClientSecret(clientSecret);
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
执行此代码时,它会发出一个请求,其中 grant_type 位于 post 值中,但 clientId 和客户端密码被放入带有经典基本身份验证标头的标头中:
Authorization: Basic bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0
如果我解码字符串 bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0
decode64(bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0) -> my-client-id:my-client-secret
这通常很好。但是我们必须使用的 Web 服务不支持这一点,我们必须将 client-id 和 client-secret 放在像 grant-type 这样的 post 值中。
有没有办法做到这一点?一种配置如何发送 client-id 和 client-secret 的方法?
迈克尔
【问题讨论】:
标签: spring spring-security spring-boot spring-security-oauth2 spring-cloud