【发布时间】:2018-12-13 07:03:46
【问题描述】:
我无法从用于发回用户详细信息的 REST 控制器获得正确响应。使用 Spring Boot 1.5.10。这是设置:
- OAuth2 项目作为身份验证和授权端点
- 连接到服务器进行身份验证和授权的微服务
OAuth 服务器正在使用 WebSecurityConfigurerAdapter(顺序 2)、ResourceServerConfigurerAdapter(保护 oauth 以外的 api)、AuthorizationServerConfigurerAdapter(oauth 配置)和GlobalAuthenticationConfigurerAdapter(ldap 与数据库身份验证)。
我有一个资源 /api/v1/me 可以在 OAuth 服务器和微服务中返回 Principal/Authentication 对象。微服务行为正确,并在存在正确的 Bearer 令牌时返回 OAuth2Authentication,否则返回 401(可以从 OAuth 服务器获取令牌)。
另一方面,OAuth 服务器给我带来了一些问题。它仅在我首先请求令牌(建立 JSession)时返回 /me 响应,否则将我转发到登录页面。 (我在 Thymeleaf 中使用 authorization_code 授权)。在这种情况下,我得到 UsernamePasswordAuthenticationToken。
是否可以将服务器配置为使用 Bearer 进行身份验证 /me 并返回 OAuth2Authentication 或 401 与 OAuth 服务器本身上的 Java 会话,我只需要通过用户名 auth 获取令牌本身?
谢谢
【问题讨论】:
标签: spring-boot authentication oauth-2.0