I've been trying to implement a group based authorization. I have gone ahead and implemented the user based authorization using the content below: https://medium.com/medialesson/role-based-authorization-in-azure-functions-with-azure-ad-and-app-roles-b1fed5714c91
Using this content, does anyone know how to change my code, so it is able to handle groups, not roles? I went ahead and changed the manifest in Azure to include securitygroups. Any help would be appreciated. Below is the code:
internal class RoleAuthorizeAttribute : FunctionInvocationFilterAttribute
{
...
public override async Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken)
{
if (!executingContext.Arguments.ContainsKey("principal"))
{
throw new AuthorizationException("Authentication failed. Missing claims.");
}
var claimsPrincipal = (ClaimsPrincipal)executingContext.Arguments["principal"];
var roles = claimsPrincipal.Claims.Where(e => e.Type == "roles").Select(e => e.Value);
var isMember = roles.Intersect(_validRoles).Count() > 0;
if (!isMember)
{
throw new AuthorizationException("Authentication failed. User not assigned to one of the required roles.");
}
}
}
claimsPrincipal.Claims.Where(e => e.Type == "groups")
? – Allen Wu