【发布时间】:2019-01-07 00:50:00
【问题描述】:
我看到 Spring Security Oauth2 有不同的授权类型:
https://projects.spring.io/spring-security-oauth/docs/oauth2.html#grant-types
如何使用不是password 的授权类型?
我目前正在使用基于密码的身份验证。
$ curl -u client:123456 http://localhost:8080/oauth/token -d grant_type=password -d username=admin -d password=admin -d client_id=client -d client_secret=123456 -d scope=write
{"access_token":"40add879-3be3-4d94-b969-4dc17975c659","token_type":"bearer","refresh_token":"583eb284-3318-432b-a8a3-b3eee744c9b7","expires_in":40688,"scope":"write"}
我注释掉了
@EnableAuthorizationServer
public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.tokenStore(this.tokenStore).userDetailsService(userDetailsService);
// .authenticationManager(new AuthenticationManager() {
// @Override
// public Authentication authenticate(Authentication authentication)
// throws AuthenticationException {
// return authenticationManagerBuilder.getOrBuild().authenticate(authentication);
// }
// });
因此它将不再使用密码授权类型。 (“通过注入 AuthenticationManager 开启密码授权”)。
然后我在 API 中搜索“grant”
https://docs.spring.io/spring-security/oauth/apidocs/index.html
然后我尝试了
$ curl -u client:123456 http://localhost:8080/oauth/token -d grant_type=token -d client_id=client -d client_secret=123456 -d scope=write
{"error":"unsupported_grant_type","error_description":"Unsupported grant type: token"}
$ curl -u client:123456 http://localhost:8080/oauth/token -d grant_type=client -d client_id=client -d client_secret=123456 -d scope=write
{"error":"unsupported_grant_type","error_description":"Unsupported grant type: client"}
$ curl -u client:123456 http://localhost:8080/oauth/token -d grant_type=code -d client_id=client -d client_secret=123456 -d scope=write
{"error":"unsupported_grant_type","error_description":"Unsupported grant type: code"}
那么,如何在不使用数据库中的用户名和密码的情况下创建仅客户端/秘密授权类型来获取访问令牌?我在任何地方都找不到有效的grant_types 列表!
这似乎是定义允许的授权类型的方法,但它没有指定有效值。
【问题讨论】:
标签: spring spring-security oauth-2.0 spring-security-oauth2 spring-oauth2