Skip to content

Commit 687934c

Browse files
committed
feat(HttpApi): Added a new security scheme and requirement to Swagger, allowing users to authenticate in the UI using static tokens
Signed-off-by: Charles d'Avernas <[email protected]>
1 parent 7bd32f0 commit 687934c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/api/Synapse.Api.Http/Extensions/IServiceCollectionExtensions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ public static IServiceCollection AddSynapseHttpApi(this IServiceCollection servi
6666
var action = (ControllerActionDescriptor)o.ActionDescriptor;
6767
return $"{action.ActionName}".ToCamelCase();
6868
});
69+
builder.AddSecurityDefinition("Static Token", new OpenApiSecurityScheme
70+
{
71+
Description = "Static token authorization using the Bearer scheme",
72+
Name = "Authorization",
73+
In = ParameterLocation.Header,
74+
Type = SecuritySchemeType.Http,
75+
Scheme = "bearer",
76+
BearerFormat = "Static Token"
77+
});
78+
builder.AddSecurityRequirement(new()
79+
{
80+
{
81+
new()
82+
{
83+
Reference = new()
84+
{
85+
Id = "Static Token",
86+
Type = ReferenceType.SecurityScheme
87+
}
88+
},
89+
Array.Empty<string>()
90+
}
91+
});
6992
builder.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
7093
builder.SwaggerDoc("v1", new OpenApiInfo
7194
{

0 commit comments

Comments
 (0)