我一直在尝试实施基于组的授权。我已经继续使用以下内容实现了基于用户的授权: https ://medium.com/medialesson/role-based-authorization-in-azure-functions-with-azure-ad-and-app-roles-b1fed5714c91
使用此内容,有谁知道如何更改我的代码,以便它能够处理组,而不是角色?我继续更改 Azure 中的清单以包含安全组。任何帮助,将不胜感激。下面是代码:
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.");
}
}
}