Outline

Demo: Implement Swagger Authorization

In the Conduit.Api Project, modify the Startup.cs file

Modify the ConfigureServices Method
  • Find the line that reads: services.AddSwaggerGen...
Paste the following code on the next line after c.SwaggerDoc…
    c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
    {
       Name = "Authorization",
       Type = SecuritySchemeType.ApiKey,
       Scheme = "Bearer",
       BearerFormat = "JWT",
       In = ParameterLocation.Header,
       Description = "JWT Authorization header using the Bearer scheme."
    });
    c.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
       {
          new OpenApiSecurityScheme
          {
             Reference = new OpenApiReference
             {
                Type = ReferenceType.SecurityScheme,
                Id = "Bearer"
             }
          },
          new string[] {}
       }
    });

This will allow Swagger to accept the pass the Auth Token back to the Web API.

 

I finished! On to the next chapter