Last active
June 25, 2020 01:02
-
-
Save PradeepLoganathan/5d5572eff6d67af1051b4e0e4face10d to your computer and use it in GitHub Desktop.
OAS 3 for .net core 3.1 using swashbuckle 5- Adding a bearer Security definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| services.AddSwaggerGen(options => | |
| { | |
| var apiinfo = new OpenApiInfo | |
| { | |
| Title = "theta-CandidateAPI", | |
| Version = "v1", | |
| Description = "Candidate API for thetalentbot", | |
| Contact = new OpenApiContact | |
| { Name = "thetalentbot", Url = new Uri("https://thetalentbot.com/developers/contact") }, | |
| License = new OpenApiLicense() | |
| { | |
| Name = "Commercial", | |
| Url = new Uri("https://thetalentbot.com/developers/license") | |
| } | |
| }; | |
| OpenApiSecurityScheme securityDefinition = new OpenApiSecurityScheme() | |
| { | |
| Name = "Bearer", | |
| BearerFormat = "JWT", | |
| Scheme = "bearer", | |
| Description = "Specify the authorization token.", | |
| In = ParameterLocation.Header, | |
| Type = SecuritySchemeType.Http, | |
| }; | |
| OpenApiSecurityRequirement securityRequirements = new OpenApiSecurityRequirement() | |
| { | |
| {securityScheme, new string[] { }}, | |
| }; | |
| options.SwaggerDoc("v1", apiinfo); | |
| options.AddSecurityDefinition("jwt_auth", securityDefinition); | |
| // Make sure swagger UI requires a Bearer token to be specified | |
| options.AddSecurityRequirement(securityRequirements); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment