如何在SpringSecurityOAuth2中使用非密码授权类型?
我看到Spring Security Oauth2有不同的授权类型: 如何使用不是密码的授权类型 我目前有基于密码的身份验证工作如何在SpringSecurityOAuth2中使用非密码授权类型?,spring,spring-security,oauth-2.0,spring-security-oauth2,spring-oauth2,Spring,Spring Security,Oauth 2.0,Spring Security Oauth2,Spring Oauth2,我看到Spring Security Oauth2有不同的授权类型: 如何使用不是密码的授权类型 我目前有基于密码的身份验证工作 $ 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
$ 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”
然后我试着
$ 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\u类型的列表
这似乎是定义允许的授权类型的方法,但它没有指定有效值
对于基于客户端凭据的令牌,请使用客户端凭据
作为授权类型
$ curl -u client:123456 http://localhost:8080/oauth/token -d grant_type=client_crendentials -d client_id=client -d client_secret=123456 -d scope=write
没有类似的grant\u类型的列表,因为grant类型是使用任何人都可以实现的接口定义的。然而,目前在Spring Security OAuth2框架中,有四个主要的grant_type
是开箱即用实现的,它们是:
您可以将上述任何一项用作授权类型
我收到错误{“错误”:“无效的客户端”,“错误描述”:“未经授权的授权类型:客户端凭据”}
。尽管我添加了.authorizedGrantTypes(“客户端凭据”…
。顺便说一句,我使用的是Spring Security Oauth2 2.0.15版。我不知道为什么,但在我清理并重建了项目后,它现在可以正常工作了。客户端凭据
不是客户端凭据
对不起,至少编辑了6个字符。