Skip to content

Commit 7a28704

Browse files
committed
fix: add global security requirement for JWT authentication in Swagger configuration
1 parent 4ad07d6 commit 7a28704

File tree

1 file changed

+16
-0
lines changed
  • src/c-sharp/JakubKozera.OpenApiUi.Sample

1 file changed

+16
-0
lines changed

src/c-sharp/JakubKozera.OpenApiUi.Sample/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
BearerFormat = "JWT",
3636
Description = "Enter your JWT token in the format: Bearer {your_token}"
3737
});
38+
39+
// Add global security requirement - endpoints can opt out with [AllowAnonymous]
40+
c.AddSecurityRequirement(new OpenApiSecurityRequirement
41+
{
42+
{
43+
new OpenApiSecurityScheme
44+
{
45+
Reference = new OpenApiReference
46+
{
47+
Type = ReferenceType.SecurityScheme,
48+
Id = "Bearer"
49+
}
50+
},
51+
Array.Empty<string>()
52+
}
53+
});
3854
});
3955

4056
// Register custom services - using direct instantiation as workaround

0 commit comments

Comments
 (0)