当前位置:网站首页>Swagger3 integrates oauth2 authentication token
Swagger3 integrates oauth2 authentication token
2022-06-23 06:55:00 【zetor_ major】
introduce swagger3
<!--Swagger3 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
Swagger3 stay header in , Conduct Authorization token Certification of , The configuration file :
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30).pathMapping("/")
// Define whether to turn on swagger,false To close , It can be controlled by variables
.enable(swaggerProperties.getEnable())
// take api The meta information of is set to be included in json ResourceListing Response .
.apiInfo(apiInfo())
// Interface debugging address
.host(swaggerProperties.getTryHost())
// Choose which interfaces to use as swagger Of doc Release
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
// Set of supported communication protocols
.protocols(newHashSet("https", "http"))
.securitySchemes(securitySchemes())
.securityContexts(securityContexts());
}
/**
* Authenticated security context
*/
private List<SecurityScheme> securitySchemes() {
List<SecurityScheme> securitySchemes = new ArrayList<>();
securitySchemes.add(new ApiKey("Authorization", "Authorization", "header"));
return securitySchemes;
}
/**
* Authorization information global application
*/
private List<SecurityContext> securityContexts() {
List<SecurityContext> securityContexts = new ArrayList<>();
securityContexts.add(SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.any()).build());
return securityContexts;
}
private 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("Authorization", authorizationScopes));
return securityReferences;
}
visit swagger3 , Address :http://127.0.0.1:8080/swagger-ui/index.html,
Click on Authorize

Input token:

Save as follows

Source code address :
边栏推荐
- Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
- mysql 基础查询
- Badly placed ()‘s 问题
- Open source ecology 𞓜 super practical open source license basic knowledge literacy post (Part 2)
- English grammar_ Adverb - ever / once
- 杂七杂八的东东
- 2121. sum of intervals of the same elements - hash table method
- core. What is JS ---kalrry
- MySQL basic query
- ssm + ftp +ueditor
猜你喜欢

swagger3整合oauth2 认证token

【系统】右键桌面图标,转圈后,资源管理器就崩溃,桌面就重新刷新

haas506 2.0开发教程-高级组件库-modem.sms(仅支持2.2以上版本)

Chrome删除重复书签

Linux Installation mysql8.0.25

【STL】关联容器之unordered_map用法总结

English grammar_ Adjective comparative - Level 3 change

cmder

How to realize video call and live interaction in a small program when live broadcasting is so popular?

Network architecture from Wan to sd-wan edge devices
随机推荐
Topic35——34. Find the first and last positions of elements in a sorted array
SAP execution transaction code mrrl error -no message was found for partner 100065-
Mongodb record
Badly placed ()‘s 问题
How to view native IP
mingw-w64、msys和ffmpeg的配置与编译
【STL】关联容器之map用法总结
Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
Cloud box is deeply convinced to create a smart dual-mode teaching resource sharing platform for Nanjing No. 1 middle school
关于五险一金你需要知道的事情
Get to know webassembly quickly
Usage Summary of item views and item widgets controls in QT
core.js是什么---kalrry
Anti chicken soup speech
WPF Command指令和INotifyPropertyChanged
Measurement principle and thickness measurement mode of spectral confocal
项目_过滤器Filter解决中文乱码
English grammar_ Adjective comparative - Level 3 change
2022-01-12: give a positive array arr, length N, subscript 0~n-1, a
XShell7 下载