public ApiIdentityResult ChangePasswordWithToken(string username, string token, string newPassword) { ApiIdentityResult result = new ApiIdentityResult(); try { using AmazonCognitoIdentityProviderClient userProvider = GetCognitoIdentityProvider(); string poolID = CognitoSettings.Values.UserPoolId; string clientID = CognitoSettings.Values.UserPoolClientId; string clientSecret = CognitoSettings.Values.UserPoolClientSecret; _pool = new CognitoUserPool(poolID, clientID, userProvider, clientSecret); var cancellationToken = new CancellationToken(); _pool.ConfirmForgotPassword(username, token, newPassword, cancellationToken).ConfigureAwait(false).GetAwaiter() .GetResult(); result.Succeeded = true; result.Token = token; } catch (Exception ex) { result.SetFailed(-200, ex.Message); result.Succeeded = false; result.Failed.Code = -200; result.Failed.Description = ex.Message; } return(result); }
/// <summary> /// Resets the <paramref name="user"/>'s password to the specified <paramref name="newPassword"/> after /// validating the given password reset <paramref name="token"/>. /// </summary> /// <param name="user">The user whose password should be reset.</param> /// <param name="token">The password reset token to verify.</param> /// <param name="newPassword">The new password to set if reset token verification succeeds.</param> /// <returns> /// The <see cref="Task"/> that represents the asynchronous operation, containing the <see cref="IdentityResult"/> /// of the operation. /// </returns> public virtual async Task <IdentityResult> ChangePasswordWithTokenAsync(TUser user, string token, string newPassword, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { await _pool.ConfirmForgotPassword(user.Username, token, newPassword, cancellationToken).ConfigureAwait(false); return(IdentityResult.Success); } catch (AmazonCognitoIdentityProviderException e) { return(IdentityResult.Failed(_errorDescribers.CognitoServiceError("Failed to change the Cognito User password", e))); } }