public bool isHRTeam(IEnumerable <Claim> userClaims) { AADGraph graph = new AADGraph(AppSettings); string groupName = "HRTeam"; string groupId = AppSettings.AADGroups.FirstOrDefault(g => String.Compare(g.Name, groupName) == 0).Id; return(graph.IsUserInGroup(userClaims, groupId).Result); }
public async Task <IActionResult> Contact() { AADGraph graph = new AADGraph(AppSettings); //Check if user is in group string groupName = "Admins"; string groupId = AppSettings.AADGroups.FirstOrDefault(g => String.Compare(g.Name, groupName) == 0).Id; bool isIngroup = await graph.IsUserInGroup(User.Claims, groupId); return(View()); }
private async Task <bool> CheckIfUserIsAnAdmin() { // AAD usage example AADGraph graph = new AADGraph(AppSettings); string groupName = "Admins"; string groupId = AppSettings.AADGroups.FirstOrDefault(g => String.Compare(g.Name, groupName) == 0).Id; bool isIngroup = await graph.IsUserInGroup(User.Claims, groupId); return(isIngroup); }
public async Task <IActionResult> Contact() { ViewData["Message"] = "Your contact page."; AADGraph graph = new AADGraph(AppSettings); string groupName = "Admins"; string groupId = AppSettings.AADGroups.FirstOrDefault(g => String.Compare(g.Name, groupName) == 0).Id; bool isIngroup = await graph.IsUserInGroup(User.Claims, groupId); return(View()); }
private async Task OnTokenValidated(TokenValidatedContext arg) { AADGraph graph = new AADGraph(_appSettings); string groupName = "Admins"; string groupId = _appSettings.AADGroups.FirstOrDefault(g => g.Name == groupName)?.Id; bool isAdmin = await graph.IsUserInGroup(arg.Principal.Claims, groupId); if (isAdmin) { arg.Principal.AddIdentity(new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.Role, Roles.Admin) })); } }
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, InAdminsGroupRequirement requirement) { AppSettings appSettings = _configuration.GetSection("AppSettings").Get <AppSettings>();; AADGraph graph = new AADGraph(appSettings); string groupName = "Admins"; string groupId = appSettings.AADGroups.FirstOrDefault(g => String.Compare(g.Name, groupName) == 0).Id; Task <bool> isIngroup = graph.IsUserInGroup(context.User.Claims, groupId); if (isIngroup.Result) { context.Succeed(requirement); } return(Task.CompletedTask); }