//在security oauth2 中给token续期
//将RedisTokenStore.java 复制一份更改readAuthentication 方法
//在授权服务器endpoints.tokenStore(new RedisTokenStore(redisConnectionFactory)) 注入更改的RedisTokenStore
@Override
public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {
log.debug("token续签开始");
OAuth2Authentication result = this.readAuthentication(token.getValue());
log.debug(JSON.toJSONString(result));
if (result != null) {
//如果token失效更新token时间
DefaultOAuth2AccessToken oAuth2AccessToken = (DefaultOAuth2AccessToken) token;
int expiresIn = oAuth2AccessToken.getExpiresIn();
log.debug("token将在{}秒后过期", expiresIn);
int second = 60 * 60 * 30;
if (expiresIn < second) {
oAuth2AccessToken.setExpiration(new Date(System.currentTimeMillis() + (second * 1000L)));
}
//将重新设置过的token过期时间设置到redis 此时会覆盖原本的过期时间
storeAccessToken(token, result);
log.debug("token过期已续期");
}
return result;
}
在security oauth2 中给token续期
于 2020-07-23 17:58:56 首次发布