微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。