我想将连接到我的 OAuth2 客户端的用户列入白名单,但我不知道如何获取用户名(特别是 Google 电子邮件地址)。
我基于 Spring 教程创建了一个 Spring Boot OAuth2 应用程序
https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_manual https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_manual
我正在通过 Google 进行身份验证(成功)。我想确定用户的电子邮件地址,以便我可以将身份验证用户列入白名单。
这个网站,
http://www.baeldung.com/spring-security-openid-connect#filter http://www.baeldung.com/spring-security-openid-connect#filter
建议我可以解压从 Google 返回的“id_token”,如下所示:
/**
* logic to unpack a ConnectID id_token like what we get from Google -
* see "Spring Security and OpenID Connect" - heading '4. Custom OpenID Connect Filter':
* http://www.baeldung.com/spring-security-openid-connect#filter
*
* @param oa2token
* @return
*/
private static UsernamePasswordAuthenticationToken getOpenIDDataForToken(OAuth2AccessToken oa2token)
{
try {
String idToken = oa2token.getAdditionalInformation().get("id_token").toString();
Jwt tokenDecoded = JwtHelper.decode(idToken);
Map<String, String> authInfo = new ObjectMapper().readValue(tokenDecoded.getClaims(), Map.class);
OpenIdConnectUserDetails user = new OpenIdConnectUserDetails(authInfo, oa2token);
return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
} catch (InvalidTokenException e) {
throw new BadCredentialsException("Could not obtain user details from token", e);
}
}
但我无法编译这段代码 -我不知道如何上课 JtwHelper
!
我四处搜寻,以下可能是正确的Maven
依赖性:
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-jwt -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
但是将其添加到我的 pom.xml 中并没有帮助 - 我没有在我的 .m2 存储库中得到真正的 Jar 文件 - 我得到一个文本文件!最重要的是,Eclipse 无法解析类型JwtHelper
.
Help?我不确定我哪里出错了。