首页 > 解决方案 > Spring Boot 中的 OAuth2 - 云

问题描述

我想创建支持 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>

应用程序.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 调用可能会被负载均衡器重定向到每个实例。

我做了一个简单的测试:

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

标签: javaspring-bootoauth-2.0spring-cloudapi-gateway

解决方案


推荐阅读