Skip to content

Commit

Permalink
Adjust authorization check to include AllowAnonymous attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Sep 24, 2024
1 parent eb517b1 commit 7c7ac85
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public void Apply(ApplicationModel application)
routeTemplate,
StringComparison.OrdinalIgnoreCase) ?? false);

//give priority to authorize attribute
var hasAuthorizeAttribute = controller.Attributes.OfType<AuthorizeAttribute>().Any();
//give priority to Authorize and AllowAnonymous attributes
var hasAuthAttributes = controller.Attributes.OfType<AllowAnonymousAttribute>().Any() ||
controller.Attributes.OfType<AuthorizeAttribute>().Any();

if (isInRouteTemplate && !hasAuthorizeAttribute)
if (isInRouteTemplate && !hasAuthAttributes)
controller.Filters.Add(new AuthorizeFilter(policyName));
}
}
Expand Down

0 comments on commit 7c7ac85

Please sign in to comment.