小编Ric*_*nte的帖子

使用 Spring Boot 应用程序作为资源服务器,使用 google oauth2 作为授权服务器

我有一个网络应用程序,使用 angular6 作为前端,使用 spring boot 作为其余 api。

我的角度应用程序在 localhost:4200 上运行,并且能够成功通过 google 进行身份验证,我可以看到 authToken 和 idToken。(我在角度中使用了angularx-social-login插件)

现在,我想使用此身份验证令牌来保护在 localhost:8080 运行的 spring boot api 服务器。

我正在尝试做类似的事情(图片来源图片 这里的客户端是我的角度应用程序,资源服务器是 Spring Boot 应用程序,授权服务器是 google

我尝试使用 EnableResourceServer 注释和许多不同的方法,但似乎没有任何效果。它总是通过检查内存令牌存储给我无效的令牌,甚至不尝试使用谷歌验证正确的令牌。

我在 Spring 应用程序和 Angular 应用程序中的 oauth2 配置中使用相同的客户端 ID 和密钥。

如何让 Spring Boot 应用程序针对每个请求使用 google 验证令牌?

我的应用程序属性

server.servlet.context-path=/api

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:file:~/h2/testdb

logging.level.org.springframework.web=TRACE
logging.level.org.springframework.security=TRACE
logging.level.org.hibernate=TRACE
    
security.oauth2.resource.filter-order = 3
spring.security.oauth2.client.registration.google.client-id=#google-client-id
spring.security.oauth2.client.registration.google.client-secret=#google-client-secret    
security.oauth2.resource.user-info-uri= https://www.googleapis.com/oauth2/v3/userinfo # URI of the user endpoint.
Run Code Online (Sandbox Code Playgroud)

这是我的资源服务器配置类

server.servlet.context-path=/api

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:file:~/h2/testdb

logging.level.org.springframework.web=TRACE
logging.level.org.springframework.security=TRACE
logging.level.org.hibernate=TRACE
    
security.oauth2.resource.filter-order = 3 …
Run Code Online (Sandbox Code Playgroud)

google-oauth spring-boot angular

5
推荐指数
1
解决办法
2802
查看次数

标签 统计

angular ×1

google-oauth ×1

spring-boot ×1