【发布时间】:2017-10-11 14:23:36
【问题描述】:
我正在关注https://spring.io/guides/tutorials/spring-boot-oauth2/,到目前为止一切正常。实际上,我什至还设法将 Google Oauth 连接为第二个身份验证提供程序。现在我正在尝试从后端的令牌信息端点读取信息,以将其与本地数据库同步并调整输出。但我不知何故努力检索信息。
本教程有时会创建此端点:
@RequestMapping("/user")
public Principal user(Principal principal) {
return principal;
}
调用时,它会正确显示(成功登录后)
{
"authorities": [...],
"details": {...},
"authenticated": true,
"userAuthentication": {
"authorities": [...],
"details": {
"email": "foo@bar.com",
"name": "Foo Bar",
"id": "12345674890000"
},
"authenticated": true,
"principal": "12345674890000",
"credentials": "N/A",
"name": "12345674890000"
},
"oauth2Request": {},
"clientOnly": false,
"credentials": "",
"principal": "12345674890000",
"name": "12345674890000"
}
因此,Spring Boot 安全性以某种方式获取了正确的信息。现在我正在尝试构建一个Interceptor(基本功能正在运行,每个请求都会调用拦截器)来处理这些信息。我正在努力获得例如现在的电子邮件地址。我找到this 答案,但它指的是旧版本的spring boot,只是链接到一个新接口,但我想知道我是否需要它(对于我认为的简单用例来说,它看起来也很复杂) .在我的 spring 应用程序中从这个 /user 端点获取信息而不实际调用我自己的端点来检索它的最佳方法是什么?
我唯一能找到的是通过SecurityContextHolder 原则 ID 和其他对我没有帮助的东西。我实际上并没有检索到例如电子邮件地址。
【问题讨论】:
标签: java spring spring-boot spring-security oauth