Spring Boot Application to validate oauth2 token from Google

Man*_*rte 5 java oauth-2.0 spring-boot spring-security-oauth2

I have my Spring Boot application, that provides some rest endpoints. Those rest endpoints need security, and I want to use the Oauth2 for it.

My idea is to use Google oauth2 token for that. I don't want to provide login functionality in my Spring Boot app, so I just want to check that the Bearer token is there and get the user info from it to display his/her data accordingly.

I'm checking this tutorial, but I don't think it's exactly what I want

https://www.baeldung.com/spring-security-5-oauth2-login

小智 1

我想解释一下在决定安全方法时应考虑的一些场景:

  1. 如果您的应用程序用户存在于谷歌中,意味着用户拥有谷歌帐户,那么您可以使用谷歌授权服务器 oauth 2.0 https://developers.google.com/identity/protocols/OAuth2,在这种情况下,您应该在谷歌开发者门户上注册,用户身份验证成功后,应用程序将收到访问和刷新令牌。之后,可以向 google 发出 OpenId 调用以获取用户信息。以上流程和集成将与以下内容相同,就像您在 Quora 应用程序上看到的“通过 google 登录”的链接一样。现在,在服务中,您可以通过 google oauth 2.0 验证端点请求验证承载令牌,并调用 userinfo 端点来获取用户信息。如果您选择 JWT 令牌,则不需要联系谷歌授权服务器进行令牌验证和用户信息调用。

  2. 第二种方法是使用 springBoot 构建自己的 oauth 2.0 服务器 - https://spring.io/guides/tutorials/spring-boot-oauth2/ 使用 API 网关层进行令牌验证,并可以使用 spring security 对微服务进行进一步授权。