我正在尝试为我的Spring Boot授权服务器(通过@EnableAuthorizationServer创建)实现Silent Authentication,以便可以从SPA请求新的访问令牌。
我认为要做到这一点,我首先需要以某种方式说服我的OAuth2授权服务器在会话中存储已登录的用户。
我找不到有关如何在线解决问题的任何信息。 我猜想@EnableAuthorizationServer注释会以某种方式禁用会话存储,但是我无法找到发生位置。
假设我像这样“登录”我的Auth Server:
curl -X POST \
http://localhost:8080/oauth/token \
-H 'Authorization: Basic Y2xpZW50OnNlY3JldA==' \
-H 'content-type: multipart/form-data \
-F grant_type=password \
-F username=demo \
-F password=demo
当然,以上内容将为我提供访问令牌。但是,我希望Auth Server使用户保持会话状态,以便我无需访问令牌即可访问下面的控制器:
// This controller is in my Auth Server
@RestController
public class SecurityController {
@GetMapping("silentauth")
public String silentAuth(Principal principal) {
return principal.toString();
}
}
这个想法是,一旦实现了上述功能,便可以为“刷新令牌”提供端点,授权服务器仅在用户当前“登录”该服务器时才提供新令牌。