将多个客户端添加到Spring OAuth2 Auth Server

我有Spring OAuth授权服务器,我想增加对一个以上client(id)的支持。我这样配置客户端:

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);

我可以使用第一个客户端获取访问令牌,但是尝试使用第二个客户端获取访问令牌时出现此错误:

{

"timestamp": 1456822249638,

"status": 401,

"error": "Unauthorized",

"message": "Bad credentials",

"path": "/oauth/token"

}

是否可以添加多个客户端,以及如何添加呢?那么,如何从数据库读取客户端?

回答:

不要使用多个inMemory构建器,而是将多个withClients 连接在一个内部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 的全部内容, 来源链接: utcz.com/qa/416127.html

回到顶部