NestJS Swagger authentication with Keycloak

19 Views Asked by At

I'm using the below swagger configuration for Keycloak authentication.

const swaggerConfig = new DocumentBuilder()
.addOAuth2({
  type: 'oauth2',
  flows: {
    implicit: {
      authorizationUrl: 'http://localhost:8080/realms/hello/protocol/openid-connect/auth',
      tokenUrl: 'http://localhost:8080/realms/hello/protocol/openid-connect/token',
      scopes: {}
    }
  }
})
.build();

I can see the "Authorize" button in Swagger. enter image description here

When I execute the workflow, I'm prompted to enter the username and password in Keycloak. After successful authentication, I get an error screen.

enter image description here

The URL has the correct info.

http://localhost:3300/api/oauth2-redirect.html#state=VGh1IEZ...aW1lKQ%3D%3D&session_state=679b34f5-61f5-4f45-810f-712de907cf7c&access_token=eyJhbGciOiJS...M4In0&token_type=Bearer&expires_in=900

Is anything broken in Swagger authentication with Keycloak in NestJS?

0

There are 0 best solutions below