首页 > 解决方案 > 如何在隐式 Oauth2 流的授权 URL 中将 response_type 更改为 id_token

问题描述

我有以下 OpenAPI 配置

   new OpenAPI()
                .components(
                        new Components()
                                .addSecuritySchemes("oAuthScheme", new SecurityScheme()
                                        .type(SecurityScheme.Type.OAUTH2)
                                        .description("This API uses OAuth 2 with the implicit grant flow.")
                                        .flows(new OAuthFlows()
                                                .implicit(new OAuthFlow()
                                                        .authorizationUrl("http://example.com/oauth2/default/v1/authorize")
                                                        .scopes(new Scopes()
                                                                .addString("openid", "read user information")
                                                        )

                                                )
                                        )
                                )
                )

当我单击招摇 UI 上的授权按钮时,它正在生成以下 URL

http://example.com/oauth2/default/v1/authorize?nonce=nonce&response_type=token&client_id=client-id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fswagger-ui%2Foauth2-redirect.html&scope=openid&state=U2F0IEphbiAwMiAyMDIxID

我想要 response_type 作为 id_token 代替令牌。有什么办法可以改变吗?

标签: swagger-uispringdocspringdoc-openapi-ui

解决方案


看来您正在使用 openidconnect。

您应该切换到 SecurityScheme = OPENIDCONNECT 并填写您的 openIdConnectUrl 网址。结果,您将在响应中获得 id_token。


推荐阅读