首页 > 解决方案 > 我可以在我的 Spring Boot 应用程序中使用来自谷歌的 id_token 吗?

问题描述

当我使用 google oauth2 保护我的 Spring Boot 应用程序时,是否可以捕获 ID 令牌?

当我使用邮递员 + keycloak 获取访问令牌时,我会得到以下信息:

{
  "access_token": "eyJhbGc...",
  "expires_in": 3600,
  "refresh_expires_in": 8640,
  "refresh_token": "eyJhbG...",
  "token_type": "Bearer",
  "id_token": "eyJhbG...",
  "not-before-policy": 0,
  "session_state": "779e9b7b-ae44-...",
  "scope": "openid email profile"
}

有id_token。用户使用谷歌登录后,是否可以在我的 Spring Boot 应用程序中获取此 id_token?

我想要可以使用但来自谷歌的类似 ID 令牌。我有一个这样的控制器,但没有发现我是否可以拥有这个 ID 令牌并使用它的声明。

@GetMapping("/userinfo")
public String userinfo() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    System.out.println(authentication.getAuthorities().toString());

    return "Userinfo...";
}

提前致谢

标签: spring-bootspring-securityoauth-2.0

解决方案


推荐阅读