zoukankan      html  css  js  c++  java
  • spring-boot swagger2 设置全局token,说明页面接口无法带入token

    1、swagger配置类

    // 验证
        private List<ApiKey> securitySchemes() {
            List<ApiKey> apiKeyList = new ArrayList();
            apiKeyList.add(new ApiKey("token", "token", "header"));
            return apiKeyList;
        }
    
        private List<SecurityContext> securityContexts() {
            List<SecurityContext> securityContexts = new ArrayList<>();
            securityContexts.add(SecurityContext.builder().securityReferences(defaultAuth())
                    .forPaths(PathSelectors.regex("^(?!auth).*$"))//过滤要验证的路径
                    .build());
            return securityContexts;
        }
    
        //增加全局认证
        List<SecurityReference> defaultAuth() {
            AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
            AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
            authorizationScopes[0] = authorizationScope;
            List<SecurityReference> securityReferences = new ArrayList<>();
            securityReferences.add(new SecurityReference("token", authorizationScopes));//验证增加(有许多教程说明中这个地方是Authorization,导致不能带入全局token,因为securitySchemes()方法中header写入token,所以这个地方我改为token就可以了)
            return securityReferences;
        }
    
        /**
         * 添加摘要信息
         */
        private ApiInfo apiInfo() {
            // 用ApiInfoBuilder进行定制
            return new ApiInfoBuilder()
                    .title("接口文档")
                    //.description("用于说明接口使用")
                    //.contact(new Contact("minhope", null, null))
                    .version("版本号:" + Global.getSwaggerDescribeVersion()).build();
        }
    

      

      

      

  • 相关阅读:
    scrapy框架之comand line tool
    CSS选择器与XPath语言
    Selenium之Web页面滚动条滚操作
    Selenium+Chrome+PhantomJS 爬取淘宝
    爬取今日头条中的图片
    django 和 mongdb 写一个简陋的网址,以及用django内置的分页功能
    charts 画饼图
    charts 画折线图
    oracle的char和varchar类型
    ORA-02049: 超时: 分布式事务处理等待锁的解决方法
  • 原文地址:https://www.cnblogs.com/webttt/p/12016135.html
Copyright © 2011-2022 走看看