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

dplesa:

我有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"
}

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

阿里·德加尼(Ali Dehghani):

不要使用多个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");
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot + Oauth2客户端凭据

Spring Security OAuth2客户端-重定向过多

了解OAuth2客户端凭据流程

Spring Security OAuth2中的auth_code授予是否可以进行匿名身份验证?

使用OAuth2的API网关的客户端凭据

Spring OAuth2 Auth Server:特定的/ oauth / token过滤器?

Spring Security中具有密码授予权限的oAuth2客户端

在NoSQL数据库中实现Spring oauth2客户端数据存储

jhipster oauth2客户端机密

Identity Server(OAuth2)实现,与旧版系统(Forms Auth,ADFS,AD)集成

OAuth2客户端(Python / Django)

将OAuth2访问令牌配置为typescript-angular2客户端

OAuth2:“客户端”到底是什么

如何在Spring Boot OAuth2服务器中启用多个客户端ID?

Rails-在多个模型上使用omniauth时,Google oauth2 request.env ['omniauth.auth']为零

Quarkus Rest客户端和OAuth2

Spring Security,OAUTH2,动态客户端秘密

将重定向URI添加到自动生成的Google OAuth 2.0客户端ID

OAuth2客户端身份验证春季

如何将内容添加到Spring oauth2访问令牌?

带有Spring的OAuth2的Android客户端

OAuth2错误无效的客户端

OAuth2客户端,已完成,从未调用

了解OAuth2中的客户端

没有客户端密码的 OAuth2 工具

将 google login_hint 参数添加到 Spring oauth2 AuthorizationCode 请求中

Microsoft Graph 的 OAuth2 客户端凭据流

OAuth2 客户端凭据

Spring Security Oauth2 Client 是否自动从 Spring Authorization Server 处理刷新令牌?