public static async Task <string> GetGroupObjectId(string groupname) { AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json"); try { var httpClient = new HttpClient(); var apiCaller = new ProtectedApiCallHelper(httpClient); var result = await apiCaller.GetWebApiAndReturnResultAsync($"{config.ApiUrl}v1.0/groups", Program.AuthenticationResult.AccessToken, Display); // TODO get the group is based on group name (query json result) string groupId = string.Empty; foreach (var group in JObject.Parse(result)["value"].ToList()) { if (group["displayName"].ToString() == groupname) { groupId = group["id"].ToString(); break; } } return(groupId); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
public static async Task <string> GetUserObjectId(string username) { AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json"); try { var httpClient = new HttpClient(); var apiCaller = new ProtectedApiCallHelper(httpClient); var result = await apiCaller.GetWebApiAndReturnResultAsync($"{config.ApiUrl}v1.0/users/{username}", Program.AuthenticationResult.AccessToken, Display); // TODO get the group is based on group name (query json result) string userId = JObject.Parse(result)["id"].ToString(); return(userId); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }