Swagger和OAuth2配置流程

时间:2017-02-16 14:55:18

标签: spring spring-boot oauth swagger

我正在处理使用OAuth2保护的Spring Boot应用程序。 我被要求将swagger整合到文档中。直到我需要配置授权时,这很容易。 https://springfox.github.io/springfox/docs/current/#springfox-configuration-and-demo-applications

我已阅读此文档,但无法找到哪些字段应填充哪些字段。 在我的应用程序中,如果我想要授权我需要在此图像上显示3个请求。 Three Requests

我知道swagger的配置是正确的地方。

(...)
      private ApiKey apiKey() {
        return new ApiKey("mykey", "api_key", "header");
      }
      private SecurityContext securityContext() {
        return SecurityContext.builder()
            .securityReferences(defaultAuth())
            .forPaths(PathSelectors.regex("/anyPath.*"))
            .build();
      }

      List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope
            = new AuthorizationScope("global", "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        return newArrayList(
            new SecurityReference("mykey", authorizationScopes));
      }

      @Bean
      SecurityConfiguration security() {
        return new SecurityConfiguration(
            "test-app-client-id",
            "test-app-client-secret",
            "test-app-realm",
            "test-app",
            "apiKey",
            ApiKeyVehicle.HEADER, 
            "api_key", 
            "," /*scope separator*/);
      }

      @Bean
      UiConfiguration uiConfig() {
        return new UiConfiguration(
            "validatorUrl",// url
            "none",       // docExpansion          => none | list
            "alpha",      // apiSorter             => alpha
            "schema",     // defaultModelRendering => schema
            UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,
            false,        // enableJsonEditor      => true | false
            true,         // showRequestHeaders    => true | false
            60000L);      // requestTimeout => in milliseconds, defaults to null (uses jquery xh timeout)
      }

0 个答案:

没有答案