Duy Huỳnh
Duy Huỳnh

Reputation: 141

How to configure API request to eureka client through API gateway

Follow this guide: https://medium.com/omarelgabrys-blog/microservices-with-spring-boot-intro-to-microservices-part-1-c0d24cd422c3

I don't know how to configure request must through api gateway?

In example, If i call direct to eureka client. I don't need jwt authentication in my request header. How can configure all request must be forwad to api gateway to validate authenticaton. And only request of eureka client of eureka server discovery no need to throught api gateway?

Help me, please!

Upvotes: 0

Views: 1421

Answers (1)

Faron
Faron

Reputation: 1393

Each micro-service controls its own access policy. By default, Spring Boot requires that all requests by authenticated. A micro-service may change this policy by supplying a bean of type ResourceServerConfigurer and overriding the configure method but this is only needed when you do not need authentication.

    public void configure(HttpSecurity http) {
        // This is the default behavior
        http.authorizeRequests().anyRequest().authenticated();
    }

You then instruct the API Gateway to pass the bearer token to your micro-service. This is controlled in the API Gateway's configuration. Assuming that you are using YAML for configuration, you should have an entry in the configuration to specify how to handle security.

proxy:
  auth:
    routes:
      my-route-name: oauth2

Where my-route-name is a route from the zuul entry

zuul:
  routes:
    my-route-name:
      path: /my-path
      service-id: my-service

Upvotes: 1

Related Questions