/// <summary> /// This method gets the Type, DisplayName, and Alias of the security principal using the GraphServiceClient. /// </summary> /// <param name="accessPol">The current AccessPolicyEntry</param> /// <param name="graphClient">The Microsoft GraphServiceClient with permissions to obtain the DisplayName</param> /// <returns>A string array holding the Type, DisplayName, and Alias if applicable</returns> private Dictionary <string, string> getTypeAndName(AccessPolicyEntry accessPol, GraphServiceClient graphClient) { Dictionary <string, string> data = new Dictionary <string, string>(); // User try { User user = null; if (graphClient.GetType() == typeof(TestGraphClient)) { var client = (TestGraphClient)graphClient; user = (client.Users.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } else { user = (graphClient.Users.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } data["Type"] = "User"; data["DisplayName"] = user.DisplayName; data["Alias"] = user.UserPrincipalName; return(data); } catch { } // Group try { Group group = null; if (graphClient.GetType() == typeof(TestGraphClient)) { var client = (TestGraphClient)graphClient; group = (client.Groups.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } else { group = (graphClient.Groups.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } data["Type"] = "Group"; data["DisplayName"] = group.DisplayName; data["Alias"] = group.Mail; return(data); } catch { } // Application try { Application app = null; if (graphClient.GetType() == typeof(TestGraphClient)) { var client = (TestGraphClient)graphClient; app = (client.Applications.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } else { app = (graphClient.Applications.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } data["Type"] = "App"; data["DisplayName"] = app.DisplayName; return(data); } catch { } // Service Principal try { ServicePrincipal sp = null; if (graphClient.GetType() == typeof(TestGraphClient)) { var client = (TestGraphClient)graphClient; sp = (client.ServicePrincipals.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } else { sp = (graphClient.ServicePrincipals.Request().Filter($"Id eq '{accessPol.ObjectId}'").GetAsync().Result)[0]; } data["Type"] = "Service Principal"; data["DisplayName"] = sp.DisplayName; return(data); } // "Unknown Application catch { data["Type"] = "Unknown"; return(data); } }