public async Task <ActionResult> RemoveAppRoleFromUser(AddAppRoleToUserModel model) { List <ResultsItem> items = new List <ResultsItem>(); if (ModelState.IsValid) { try { var azureClient = GraphAuthService.GetActiveDirectoryClient(ConfigHelper.UseApplicationPermissions); string token = await GraphAuthService.GetTokenForApplication(ConfigHelper.UseApplicationPermissions); Tuple <bool, string, string, string, string> tup = await usersService.RemoveApplicationRoleFromUser(azureClient, token, ConfigHelper.AzureADGraphUrl, ConfigHelper.Tenant, model.AppName, model.UserEmailAddress, model.AppRoleName); // Get group members. var appRoleAssignmentsPaged = await azureClient.ServicePrincipals .GetByObjectId(tup.Item5) .AppRoleAssignedTo .ExecuteAsync(); var appRoleAssignments = await AzureADExtensions.EnumerateAllAsync(appRoleAssignmentsPaged); Guid approleid = Guid.Parse(tup.Item4); var users = appRoleAssignments .Where(a => a.Id == approleid && a.PrincipalType == "User") .Select(a => new { Id = a.PrincipalId.ToString(), Name = a.PrincipalDisplayName }) .ToList(); if (users != null) { foreach (var s in users) { items.Add(new ResultsItem() { Id = s.Id, Display = s.Name }); } } return(View("ListRoleMembers", new Tuple <bool, string, string, List <ResultsItem> >(tup.Item1, tup.Item2, model.AppRoleName, items))); } catch (Exception ex) { model.isOk = false; model.message = ex.Message + (ex.InnerException != null ? Environment.NewLine + ex.InnerException.Message : ""); } } return(View("RemoveAppRoleFromUser", model)); }
public async Task <ActionResult> GetAccessReviewDetails(string typeid, string id) { string formattedJson = ""; string status = "ERROR"; string message = "Could not complete the request"; Tuple <bool, string, string> res = new Tuple <bool, string, string>(false, "", ""); List <string> lstInstances = new List <string>(); try { var graphServiceClient = GraphAuthService.CreateGraphServiceClient(ConfigHelper.UseApplicationPermissions); string token = GraphAuthService.GetTokenForApplication(ConfigHelper.UseApplicationPermissions, false).Result; if (typeid == "1") { res = await usersService.GetAccessReviewDetails(graphServiceClient, token, ConfigHelper.GraphUrl, id); } else if (typeid == "2") { res = await usersService.GetAccessReviewReviewers(graphServiceClient, token, ConfigHelper.GraphUrl, id); } else if (typeid == "3") { res = await usersService.GetAccessReviewDecisions(graphServiceClient, token, ConfigHelper.GraphUrl, id); } if (res.Item1) { formattedJson = res.Item3;// JsonConvert.SerializeObject(res.Item3, Formatting.Indented); status = "OK"; } else { message = res.Item2; } } catch (Exception ex) { message = ex.Message + " " + (ex.InnerException != null ? ex.InnerException.Message : ""); } var jsonData = new { status = status, message = message, jresult = formattedJson }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }
public async Task <ViewResult> ListAccessReviews() { string formattedJson = ""; string status = "ERROR"; string message = "Could not complete the request"; Tuple <bool, string, string> res = new Tuple <bool, string, string>(false, "", ""); List <Tuple <string, string, string, string> > AccessReviewIDs = new List <Tuple <string, string, string, string> >(); AccessReviews ar = new AccessReviews(); string masterRecurrenceType = "", childRecurrenceType = ""; try { var graphServiceClient = GraphAuthService.CreateGraphServiceClient(ConfigHelper.UseApplicationPermissions); string token = GraphAuthService.GetTokenForApplication(ConfigHelper.UseApplicationPermissions, false).Result; res = await usersService.GetAccessReviewProgramControlList(graphServiceClient, token, ConfigHelper.GraphUrl); if (res.Item1) { formattedJson = res.Item3; JObject jObject = JObject.Parse(formattedJson); JArray values = (JArray)jObject.SelectToken("value");//this is a list of current action reviews either recurring or not foreach (JToken v in values) { string controlId = (string)v.SelectToken("controlId");//refers to action review string displayName = (string)v.SelectToken("displayName"); string startDateTime = (string)v.SelectToken("startDateTime"); string endDateTime = (string)v.SelectToken("endDateTime"); string arstatus = (string)v.SelectToken("status"); //check if this is recurring res = await usersService.GetAccessReviewDetails(graphServiceClient, token, ConfigHelper.GraphUrl, controlId); if (res.Item1) { jObject = JObject.Parse(res.Item3); masterRecurrenceType = (string)jObject.SelectToken("settings").SelectToken("recurrenceSettings").SelectToken("recurrenceType"); string det = "Name: " + displayName + " | Start Date: " + startDateTime + " | End Date: " + endDateTime + " | Status: " + arstatus; AccessReviewIDs.Add(new Tuple <string, string, string, string>(controlId, "", masterRecurrenceType, det)); if (masterRecurrenceType != "onetime") { //get instances res = await usersService.GetAccessReviewInstances(graphServiceClient, token, ConfigHelper.GraphUrl, controlId);//this would not inlcude current one if (res.Item1) { formattedJson = res.Item3;//this contains instance details jObject = JObject.Parse(formattedJson); JArray instances = (JArray)jObject.SelectToken("value");//instance array foreach (JToken v2 in instances) { string acid = (string)v2.SelectToken("id"); startDateTime = (string)v2.SelectToken("startDateTime"); endDateTime = (string)v2.SelectToken("endDateTime"); arstatus = (string)v2.SelectToken("status"); string dname = (string)v2.SelectToken("displayName"); det = "Name: " + dname + " | Start Date: " + startDateTime + " | End Date: " + endDateTime + " | Status: " + arstatus; AccessReviewIDs.Add(new Tuple <string, string, string, string>(acid, controlId, "", det)); } } else { message = res.Item2; } } } else { message = res.Item2; } } status = "OK"; } else { message = res.Item2; } } catch (Exception ex) { message = ex.Message + " " + (ex.InnerException != null ? ex.InnerException.Message : ""); } return(View(new AccessReviews() { status = (status == "OK"), resultantMessage = message, lstResult = AccessReviewIDs })); }