protected virtual async Task <IEnumerable <Claim> > SetAccountEmailAsync(TKey userID, IEnumerable <Claim> claims) { var email = claims.FirstOrDefault(x => x.Type == Constants.ClaimTypes.Email); if (email != null) { var userEmail = await userManager.GetEmailAsync(userID); if (userEmail == null) { // if this fails, then presumably the email is already associated with another account // so ignore the error and let the claim pass thru var result = await userManager.SetEmailAsync(userID, email.Value); if (result.Succeeded) { var email_verified = claims.FirstOrDefault(x => x.Type == Constants.ClaimTypes.EmailVerified); if (email_verified != null && email_verified.Value == "true") { var token = await userManager.GenerateEmailConfirmationTokenAsync(userID); await userManager.ConfirmEmailAsync(userID, token); } var emailClaims = new string[] { Constants.ClaimTypes.Email, Constants.ClaimTypes.EmailVerified }; return(claims.Where(x => !emailClaims.Contains(x.Type))); } } } return(claims); }