向Spring OAuth2 Auth Server添加多个客户端 [英] Adding more then one client to the Spring OAuth2 Auth Server
本文介绍了向Spring OAuth2 Auth Server添加多个客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Spring OAuth授权服务器,我想添加对多个客户端(id)的支持。我为这样的客户配置:
I have Spring OAuth Authorization server and I want to add support for more then one client(id). I configured clients like this:
clients
.inMemory().withClient(client).secret(clientSecret)
.resourceIds(resourceId)
.authorizedGrantTypes("client_credentials", "password", "refresh_token", "implicit", "authorization_code")
.authorities("ROLE_USER")
.scopes("read", "write")
.autoApprove(true)
.and()
.inMemory().withClient("acme").secret("acmesecret")
.resourceIds(resourceId)
.authorizedGrantTypes("client_credentials", "password", "refresh_token", "implicit", "authorization_code")
.authorities("ROLE_USER_ACME")
.scopes("read", "write")
.autoApprove(true);
我可以使用第一个客户端获取访问令牌,但在尝试获取访问令牌时出现此错误第二个客户:
I can get access token with first client, but i get this error when trying to get access token with second client:
{
"timestamp": 1456822249638,
"status": 401,
"error": "Unauthorized",
"message": "Bad credentials",
"path": "/oauth/token"
}
是否可以添加多个客户端以及如何操作?另外,如何从数据库中读取客户端?
Is it possible to add more then one client and how to do it? Allso, how to read clients from a database?
推荐答案
不要使用多个 inMemory
构建器,而是在一个 inMemory
中连接多个 withClient
:
Do not use multiple inMemory
builders, instead concatenate multiple withClient
s inside one inMemory
:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("first")
.secret("secret")
.scopes("read")
.authorizedGrantTypes("password")
.and()
.withClient("sec")
.secret("secret")
.scopes("read")
.authorizedGrantTypes("password");
}
这篇关于向Spring OAuth2 Auth Server添加多个客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文