public async Task <ApiResponse> UpdateUser(Guid objectId, AdB2cUser adB2cUser) { string url = $"{_azureAdGraphSettings.ApiUrl}/{_azureAdGraphSettings.AzureAdB2CTenant}/users/{objectId}?{_azureAdGraphSettings.ApiVersion}"; HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), url); await _azureAdGraphAuthenticationProvider.AuthenticateRequestAsync(request); var adB2cUserUpdate = new JObject { { "givenName", adB2cUser.GivenName }, { "surname", adB2cUser.Surname }, { "mobile", adB2cUser.Mobile } }.ToString(); request.Content = new StringContent(adB2cUserUpdate, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { string error = await response.Content.ReadAsStringAsync(); Log.Error($"An error ocurred when updating user profile with Azure AD Graph API: {error}"); return(new ApiResponse().SetAsFailureResponse(Errors.User.UserProfileCannotBeUpdated())); } else { return(new ApiResponse()); } }
public async Task UpdateProfile(User student) { var userProfileToUpdate = new AdB2cUser { GivenName = student.FirstName, Surname = student.LastName, Mobile = student.Phone, signInNames = new List <SignInName>() { new SignInName { type = "emailAddress", value = student.Email } } }; await _adB2cGraphClientUserPropertiesProvider.UpdateUser(student.Id, userProfileToUpdate); }