春季启动中的 OAuth2 - 云

时间:2021-06-11 09:47:14

标签: java spring-boot oauth-2.0 spring-cloud api-gateway

我想创建支持 oauth2/oidc 的 spring 云网关。已经创建了示例项目,并添加了 spring-boot-starter-oauth2-client 和 spring-boot-starter-web 依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

application.yml:

spring:
  security:
    oauth2:
      client:
        registration:
          my-provider:
            authorization-grant-type: authorization_code
            redirect-uri: https://localhost:9443/login/oauth2/code/callback
            scope:
            - openid
            client-id: xxxxxx
            client-secret: xxxxxx
            
        provider:
          my-provider:
            authorization-uri: xxxxxx
            token-uri: xxxxxx
            jwk-set-uri: xxxxxx  

我的问题是我想在云环境中运行这个应用程序,所以考虑到应用程序的许多实例,而且 api 调用可能会被负载均衡器重定向到每个实例。

我做了一个简单的测试:

  • 开始申请
  • 调用的应用程序 api
  • 重定向到 oidc 登录页面以提供凭据
  • 重新启动的应用程序(新的、不同的应用程序实例)
  • 提交的凭据
  • 重定向回应用程序,得到 “authorization_request_not_found”错误

是否可以设置 oauth 以使其更适合在云中用作多实例应用程序? 感谢一百万的任何建议!

0 个答案:

没有答案