|
@ -12,20 +12,21 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt |
|
|
public void Apply(Operation operation, OperationFilterContext context) |
|
|
public void Apply(Operation operation, OperationFilterContext context) |
|
|
{ |
|
|
{ |
|
|
// Check for authorize attribute
|
|
|
// Check for authorize attribute
|
|
|
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || |
|
|
|
|
|
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); |
|
|
|
|
|
|
|
|
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() || |
|
|
|
|
|
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any(); |
|
|
|
|
|
|
|
|
if (hasAuthorize) |
|
|
|
|
|
{ |
|
|
|
|
|
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); |
|
|
|
|
|
operation.Responses.Add("403", new Response { Description = "Forbidden" }); |
|
|
|
|
|
|
|
|
if (!hasAuthorize) return; |
|
|
|
|
|
|
|
|
|
|
|
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" }); |
|
|
|
|
|
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" }); |
|
|
|
|
|
|
|
|
operation.Security = new List<IDictionary<string, IEnumerable<string>>>(); |
|
|
|
|
|
operation.Security.Add(new Dictionary<string, IEnumerable<string>> |
|
|
|
|
|
|
|
|
operation.Security = new List<IDictionary<string, IEnumerable<string>>> |
|
|
|
|
|
{ |
|
|
|
|
|
new Dictionary<string, IEnumerable<string>> |
|
|
{ |
|
|
{ |
|
|
{ "oauth2", new [] { "locationsapi" } } |
|
|
{ "oauth2", new [] { "locationsapi" } } |
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |