@@ -17,33 +17,16 @@ namespace Umbraco.Cms.Api.Delivery.Configuration;
1717/// </remarks>
1818public class ConfigureUmbracoMemberAuthenticationDeliveryApiSwaggerGenOptions : IConfigureOptions < SwaggerGenOptions >
1919{
20- private const string AuthSchemeName = "Umbraco Member " ;
20+ private const string AuthSchemeName = "UmbracoMember " ;
2121
2222 public void Configure ( SwaggerGenOptions options )
2323 {
24- options . AddSecurityDefinition (
25- AuthSchemeName ,
26- new OpenApiSecurityScheme
27- {
28- In = ParameterLocation . Header ,
29- Name = AuthSchemeName ,
30- Type = SecuritySchemeType . OAuth2 ,
31- Description = "Umbraco Member Authentication" ,
32- Flows = new OpenApiOAuthFlows
33- {
34- AuthorizationCode = new OpenApiOAuthFlow
35- {
36- AuthorizationUrl = new Uri ( Paths . MemberApi . AuthorizationEndpoint , UriKind . Relative ) ,
37- TokenUrl = new Uri ( Paths . MemberApi . TokenEndpoint , UriKind . Relative )
38- }
39- }
40- } ) ;
41-
4224 // add security requirements for content API operations
25+ options . DocumentFilter < DeliveryApiSecurityFilter > ( ) ;
4326 options . OperationFilter < DeliveryApiSecurityFilter > ( ) ;
4427 }
4528
46- private class DeliveryApiSecurityFilter : SwaggerFilterBase < ContentApiControllerBase > , IOperationFilter
29+ private class DeliveryApiSecurityFilter : SwaggerFilterBase < ContentApiControllerBase > , IOperationFilter , IDocumentFilter
4730 {
4831 public void Apply ( OpenApiOperation operation , OperationFilterContext context )
4932 {
@@ -70,5 +53,31 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
7053 }
7154 } ;
7255 }
56+
57+ public void Apply ( OpenApiDocument swaggerDoc , DocumentFilterContext context )
58+ {
59+ if ( context . DocumentName != DeliveryApiConfiguration . ApiName )
60+ {
61+ return ;
62+ }
63+
64+ swaggerDoc . Components . SecuritySchemes . Add (
65+ AuthSchemeName ,
66+ new OpenApiSecurityScheme
67+ {
68+ In = ParameterLocation . Header ,
69+ Name = AuthSchemeName ,
70+ Type = SecuritySchemeType . OAuth2 ,
71+ Description = "Umbraco Member Authentication" ,
72+ Flows = new OpenApiOAuthFlows
73+ {
74+ AuthorizationCode = new OpenApiOAuthFlow
75+ {
76+ AuthorizationUrl = new Uri ( Paths . MemberApi . AuthorizationEndpoint , UriKind . Relative ) ,
77+ TokenUrl = new Uri ( Paths . MemberApi . TokenEndpoint , UriKind . Relative )
78+ }
79+ }
80+ } ) ;
81+ }
7382 }
7483}
0 commit comments