Search code examples
spring-bootpostmanmicroserviceskeycloakspring-cloud-gateway

Postman returning HTML login page with keycloak


I have a simple microservices project with an api-gateway, a product service and keycloak as authentication server. I beleive that i made the configuration correctly because on the browser i get the right response, but on postman what i get back as response is the keycloak default login page (on HTML).

This is the response on the browser enter image description here

This is the postman response enter image description here

Postman cookies : enter image description here Api-gateway config :

spring:
  cloud:
    gateway:
      default-filters:
        - TokenRelay
      routes:
        - id: product-resource-server
          uri: http://localhost:9191
          predicates:
            - Path=/product/**
  security:
    oauth2:
      client:
        provider:
          my-keycloak-provider:
            issuer-uri: http://localhost:2727/auth/realms/demo-microservice-realm
        registration:
          keycloak-spring-gateway-client:
            provider: my-keycloak-provider
            client-id: demo-cloud-gateway-client
            client-secret: 39ea2ef6-90a7-47ca-9892-fda60127f47e
            authorization-grant-type: authorization_code
            redirect-uri: "{baseUrl}/login/oauth2/code/keycloak"

My service config :

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          jwk-set-uri: http://localhost:2727/auth/realms/demo-microservice-realm/protocol/openid-connect/certs

server:
  port: 9191

ProductController :

@RestController
public class Controller {

    @GetMapping("/product")
//    @RolesAllowed({"product_read"})
    public String getProduct(Principal principal) {
        return "Response from Product Service, User Id:" + principal.getName();
    }
}

So what i really wanna know is if this is a postman Bug or it is a config problem (project, keycloak ...).

Actually i can't test any Post resquest for the same raison and because it not possible to test them on the browser.

I hope this is understandable.


Solution

  • Well, I added spring-boot-starter-oauth2-resource-server in the api gateway project and it works fine. Please refer to this tutorial : Microservices – Authentication, and Authorization With Keycloak