use spring cloud gateway with oauth2

前端 未结 3 792
南笙
南笙 2021-01-04 15:40

i face a problem when i using spring cloud gateway

is if any dependency call spring-boot-starter-tomcat directly or recursively

it

相关标签:
3条回答
  • 2021-01-04 15:56

    spring boot 2.1 with spring security 5 have resolve this problem see this example

    0 讨论(0)
  • 2021-01-04 16:02

    As you've seen, the Spring cloud gateway uses the reactive model and is based on netty rather than tomcat. The reactive change is a major shift and currently isn't supported by Spring Security but work is in progress on it and you can track it at https://github.com/spring-cloud/spring-cloud-gateway/issues/179

    0 讨论(0)
  • 2021-01-04 16:08

    Use the following dependencies (I copied from my build.gradle)

    dependencies {
        implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
        implementation 'org.springframework.cloud:spring-cloud-starter-security'
        implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    }
    

    Code your gateway app minimally as follows

    @SpringBootApplication
    public class App {
    
        @Bean
        public ForwardedHeaderTransformer forwardedHeaderTransformer() {
            return new ForwardedHeaderTransformer();
        }
    
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }
    }
    

    Configure in application.yml

    spring:
      security:
        oauth2:
          client:
            registration:
              google:
                client-id: XXX
                client-secret: YYY
    

    I am actively building my stack that uses OAuth2 with Docker Swarm Discovery https://github.com/trajano/spring-cloud-demo.git so you can see how it would work in action.

    0 讨论(0)
提交回复
热议问题