【问题标题】:Swagger UI - OAuth 2.0 configuration with Micronaut 2.5.1 client ID and client secret in seperate configurationSwagger UI - 带有 Micronaut 2.5.1 客户端 ID 和客户端密码的 OAuth 2.0 配置在单独的配置中
【发布时间】:2021-05-19 10:49:04
【问题描述】:

根据 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 都不同。通过像上面的代码一样设置值,很难为每个环境进行配置。有没有更好的方法来做到这一点?

【问题讨论】:

    标签: java micronaut micronaut-openapi


    【解决方案1】:

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

    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 映像,我想在其中创建一个并在之后挂载这些属性。

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 2016-03-22
      • 2013-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 2013-01-11
      • 2022-08-02
      相关资源
      最近更新 更多