public async Task <IHttpActionResult> LoalAccountSignIn() { // If not data came in, then return if (this.Request.Content == null) { throw new Exception(); } // Read the input claims from the request body string input = Request.Content.ReadAsStringAsync().Result; // Check input content value if (string.IsNullOrEmpty(input)) { return(Content(HttpStatusCode.Conflict, new B2CResponseContent("Request content is empty", HttpStatusCode.Conflict))); } // Convert the input string into InputClaimsModel object InputClaimsModel inputClaims = JsonConvert.DeserializeObject(input, typeof(InputClaimsModel)) as InputClaimsModel; if (inputClaims == null) { return(Content(HttpStatusCode.Conflict, new B2CResponseContent("Can not deserialize input claims", HttpStatusCode.Conflict))); } // Note: Azure Blob Table query is case sensitive, always set the input email to lower case TableUserEntity userMigrationEntity = UserMigrationService.RetrieveUser(inputClaims.email.ToLower()); if (userMigrationEntity != null) { // Compare the password entered by the user and the one in the migration table if (ValidateCredentials(inputClaims.email, inputClaims.password)) { try { Trace.WriteLine($"User '{inputClaims.email}' exists in migration table, password is matched, the service is updating AAD account password"); B2CGraphClient b2CGraphClient = new B2CGraphClient(this.Tenant, this.ClientId, this.ClientSecret); // Update user's password await b2CGraphClient.UpdateUserPassword(inputClaims.email, inputClaims.password); // Remove the user entity from migration table UserMigrationService.RemoveUser(inputClaims.email.ToLower()); // Wait until password is set await Task.Delay(1500); } catch (Exception ex) { Trace.TraceError(ex.Message); return(Content(HttpStatusCode.Conflict, new B2CResponseContent("Can not migrate user", HttpStatusCode.Conflict))); } } else { Trace.WriteLine($"User '{inputClaims.email}' exists in migration table, passwords do not match"); } } else { Trace.WriteLine($"No action required for user '{inputClaims.email}'"); } return(Ok()); }