在angular中使用授权码grant时如何使用spring-security-oauth2-client获取和维护oauth2令牌

a11xaf1n  于 2023-05-05  发布在  Angular
关注(0)|答案(1)|浏览(157)
How can I get the token to the front end angular application after successful redirection to the index.html page happens like
1. I have used 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>
in my pom.xml
2. then I have added required properties in my application.properties file
3. I built the angular files and placed them under resources/static folder

现在重定向到auth-server和回调到application成功发生,但如何获取oauth2令牌并存储在angular应用程序中,这将对进一步调用有用

y1aodyip

y1aodyip1#

如果你有一个Angular应用程序,那么它就是客户端。它应该使用angular-auth-oidc-client或类似的方式来:

  • 登录用户
  • 处理重定向到授权服务器
  • 访问令牌的交换授权码
  • 访问令牌刷新
  • 向发送到配置的安全路由的请求添加带有访问令牌的授权头

Spring REST API应用是资源服务器。它应该依赖于spring-boot-starter-oauth2-resource-server,而不是spring-boot-starter-oauth2-client。请参考spring Boot 文档或查看those tutorials以了解有关配置Spring resource-servers的更多详细信息。

相关问题