This is looking very good, but the swagger could be improved by using its authorization feature. I have this working, and this is what I did.
In program.cs: after the following lines, add the "// To Enable authorization using Swagger (JWT)" section of code
// To Enable authorization using Swagger (JWT)
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
{
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
Array.Empty<string>()
}
});
To use, get the bearer token, and press the green Authorize button.
In the input box type the word Bearer followed by a space and paste the bearer token. Then press the authorize button and the close button.
Features like /users/me, should now work as expected. This worked great for me, and I think should be part of the demo code.
Hope this helps.