NestJS Swagger 使用 Keycloak 进行身份验证

问题描述 投票:0回答:1

我使用下面的 swagger 配置进行 Keycloak 身份验证。

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();

我可以在 Swagger 中看到“授权”按钮。 enter image description here

当我执行工作流程时,系统会提示我在 Keycloak 中输入用户名和密码。身份验证成功后,我收到错误屏幕。

enter image description here

该网址包含正确的信息。

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

NestJS 中使用 Keycloak 进行 Swagger 身份验证有什么问题吗?

keycloak nestjs-swagger
1个回答
0
投票

如果默认在“localhost:3300/api/swagger/”或“localhost:3300/api/”末尾添加斜杠,则重定向网址将被正确配置。另请参阅https://github.com/nestjs/swagger/issues/2024

© www.soinside.com 2019 - 2024. All rights reserved.