令牌刷新时丢失身份验证详细信息

Losing authentication details on token refresh

将 spring-security-oauth2 与刷新令牌一起使用,我在从刷新的 access_token 中获取详细信息 (OAuth2Authentication.getDetails()) 时遇到问题,因为它们在 refreshAccessToken@ 中丢失了DefaultTokenServices 正如我在调试中看到的那样。首次刷新前会显示详细信息。

我在 https://github.com/spring-projects/spring-security-oauth/pull/581 中看到了一个修复程序,但三年内没有提交更改。

我很惊讶在 3 年内没有更多关于这个主题的投诉,我想知道人们是如何解决这个问题的。

经过一番调查,我已经能够按如下方式解决问题。

所有配置都被误解了,@EnableAuthorizationServer@EnableResourceServer 定义之间存在冲突。

在两个 类 中设置相同的配置,我能够使用自定义 类 扩展 TokenEnhancerJwtAccessTokenConverter.

解决问题

我还更新了最新版本的依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.3.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>