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 one

我可以看到它已经创建了以下代码的文件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而不同。通过像上面的代码一样设置值,很难为每个环境进行配置。有更好的方法吗?

在我的项目中,它是通过为每个env创建不同的属性文件并使用参数指导编译来解决的

tasks.withType(JavaCompile) {
String openapiPropertyFile = 'openapi/openapi-dev.properties'
if(project.hasProperty("openapiPropertyFile")){
openapiPropertyFile = project.property('openapiPropertyFile')
}
options.fork = true
options.forkOptions.jvmArgs << "-Dmicronaut.openapi.config.file=$openapiPropertyFile"
}

然后你像这个一样构建它

$ sh ./gradlew clean jib -PopenapiPropertyFile=openapi/openapi-uat.properties -PimageSuffix=-uat

尽管我想知道如何进行后期编译,因为在我的情况下,它会强制创建单独的docker映像,我希望在其中创建一个,然后挂载这些属性。

最新更新