Swagger UI - OAuth 2.0 配置与 Micronaut 2.5.1 客户端 ID 和单独配置中的客户端密钥

问题描述

根据 micronuat 文档,尝试在最新版本的 Micronaut 中进行 swagger OAuth 配置 https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html#enableendpoints

swagger-ui.oauth2RedirectUrl
swagger-ui.oauth2.clientId
swagger-ui.oauth2.clientSecret
swagger-ui.oauth2.realm
swagger-ui.oauth2.appName
swagger-ui.oauth2.scopeSeparator
swagger-ui.oauth2.scopes
swagger-ui.oauth2.additionalQueryStringParams
swagger-ui.oauth2.useBasicAuthenticationWithAccessCodeGrant
swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant

当设置任何这些属性时,Micronaut 不仅会生成一个 swagger-ui/index.html 文件,还会生成一个 swagger-uI/Oauth2-redirect.html 文件

我可以看到它使用以下代码创建了文件 oauth2-redirect.html

tasks.withType(JavaCompile).all {
    options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=swagger-ui.enabled=true,swagger-ui.theme=flattop,swagger-ui.oauth2RedirectUrl=http://localhost:8080/swagger-uI/Oauth2-redirect.html,swagger-ui.oauth2.clientId=myClientId,swagger-ui.oauth2.scopes=openid,swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant=true'
}

对于 oauth2.clientId、oauth2RedirectUrl 和 oauth2.clientSecret,这些值因环境 PROD、TEST、DEV、UAT 而异。通过像上面的代码那样设置值,很难为每个环境配置。有没有更好的方法来做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)