Created
May 4, 2021 08:40
-
-
Save abdusco/f70cf7d015948e99265081fc82e1dc48 to your computer and use it in GitHub Desktop.
SwashBuckle configuration for bearer tokens
This file contains 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(c => | |
{ | |
// ... | |
c.AddSecurityDefinition("bearer", new OpenApiSecurityScheme | |
{ | |
Description = | |
"Authenticate with an existing JWT token. **Prefix the token with `Bearer`, i.e. `Bearer eyJ...`**", | |
In = ParameterLocation.Header, | |
Name = HeaderNames.Authorization, | |
BearerFormat = "JWT", | |
Type = SecuritySchemeType.ApiKey, | |
}); | |
c.AddSecurityRequirement(new OpenApiSecurityRequirement | |
{ | |
// ... other security requirements | |
[new OpenApiSecurityScheme | |
{ | |
Reference = new OpenApiReference | |
{ | |
Type = ReferenceType.SecurityScheme, | |
Id = "bearer" | |
} | |
}] = new string[] { }, | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment