接口获取authorization为null
来源:3-8 读取Redis登录用户信息和清空Redis用户信息
地球是猿的
2021-08-19
老师你好,我这边设置了Bearer token后接口获取不到这个值,
所以我弄了个折中的办法从Authentication中获取,
public CommonResponse logout(String access_token, Authentication authentication) {
// 判断 access_token 是否为空,为空将 authorization 赋值给 access_token
if (StringUtils.isBlank(access_token)) {
access_token = ((OAuth2AuthenticationDetails) authentication.getDetails()).getTokenValue();
}
不知道有没有更加合适的方法
写回答
1回答
-
你也可以从header中直接获取Authentication这个参数的值,用@RequestHeader注解
012021-08-22
相似问题