I want to implement JWT authorization for my APIs . I am passing token type as Bearer Token in Authorization tab of the Postman;., this is working perfectly fine through postman
However, I want to implement same on Swagger. How to implement this? I am using .net framework and not Core.
Help would really be appreciated.

Jignesh KumarRank #91 · 22.9K reputationPosted Mar 29, 2023, 1:10 AM EDT
Hello Rohan,
Please refer ,
https://www.c-sharpcorner.com/article/authentication-authorization-using-net-core-web-api-using-jwt-token-and/
https://www.infoworld.com/article/3650668/implement-authorization-for-swagger-in-aspnet-core-6.html
https://code-maze.com/swagger-authorization-aspnet-core/
Rohan Laghate78 reputationPosted Mar 29, 2023, 1:45 AM EDT
Hi Jignesh,
I need it for .Net framework and not core.
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 29, 2023, 2:19 AM EDT
https://mattfrear.com/2017/04/27/add-an-authorization-header-to-your-swagger-ui-with-swashbuckle/
Rajkiran SwainRank #165 · 14.4K reputationPosted Mar 29, 2023, 4:29 PM EDT
To implement JWT authorization in Swagger, you can follow the below steps:
public static void Register() { GlobalConfiguration.Configuration .EnableSwagger(c => { // Add the Swagger authentication filter c.OperationFilter(); // Set the security definition c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); }) .EnableSwaggerUi(c => { c.DocumentTitle("My API"); c.InjectJavaScript(Assembly.GetExecutingAssembly(), "MyAPI.Scripts.Swagger.js"); }); }public class SwaggerAuthorizationFilter : IOperationFilter { public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { // Get the Authorization attributes var authAttributes = apiDescription.GetControllerAndActionAttributes().ToList(); // Add the Authorization header if (authAttributes.Any()) { operation.parameters.Add(new Parameter { name = "Authorization", @in = "header", description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\"", required = true, type = "string", @default = "Bearer " }); } } }[Authorize]attribute on the controller or action method to enable JWT authorization.This should enable JWT authorization in Swagger for your APIs.