【发布时间】:2016-08-12 05:53:57
【问题描述】:
我正在创建一个基于 oauth2.0 框架的受保护的 rest api。
我成功搭建了授权服务器和资源服务器。
AuthorizationServer 扩展了 AuthorizationServerConfigurerAdapter 并覆盖了一些方法,我遇到了这个扩展方法的问题
public void configure(ClientDetailsServiceConfigurer clients) 抛出异常{}
这里是解释
当我运行这个版本的 config() 授权服务器
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("clientapp").authorizedGrantTypes("password", "refresh_token")
.scopes("read", "write").resourceIds(RESOURCE_ID).secret("123456");
}
这个方法工作得很好,当我要求它时会返回一个 access_token。
但是当我运行相同的方法并进行一些增强时,当我请求 access_token 时,我什么也没得到,而是 401 未经授权的 http 响应。
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
int n = appMetier.getAppsCount();
for (App app:appMetier.findAll(0, n).getApps()) {
clients.inMemory().withClient(app.getClientPublicId()).authorizedGrantTypes("password", "refresh_token")
.scopes("read", "write").resourceIds(RESOURCE_ID).secret(app.getClientSecretId());
}
}
这里的 n 变量等于 17,这意味着我在内存中有 17 个有权接收 access_token 的客户端。
唯一从17中获得access_token的是第一个。
请您的回答,并在此先感谢。
【问题讨论】:
-
同一个 OAuth 提供者需要多个客户端?