AWS Cognito密码更改

时间:2020-04-06 11:20:28

标签: amazon-cognito

我正在尝试更改已确认的Cognito用户的密码。

我在请求中传递了一个有效令牌,但是它仍然给出无效访问令牌的错误。 我已经使用[Authorize]控制器确认了另一个请求中相同令牌的有效性,并且该令牌似乎正在工作。 下面是代码

    public async Task<IActionResult> ChangePassword(ChangePasswordDTO changePassword)
{
try
            {
                var cognito = new AmazonCognitoIdentityProviderClient(_region);
                ChangePasswordRequest confirmRequest = new ChangePasswordRequest()
                {
                     AccessToken = changePassword.AccessToken,
                     PreviousPassword = changePassword.OldPassword,
                     ProposedPassword = changePassword.NewPassword  
                };

                var confirmResult = await cognito.ChangePasswordAsync(confirmRequest);
                APIResponse apiresponse = new APIResponse();
                apiresponse.Message = "Password Changed Successfully";
                return Ok(apiresponse);
            }
            catch(UserNotConfirmedException unotcon)
            {
                APIResponse apiresponse = new APIResponse();
                apiresponse.Message = unotcon.Message;
                var result = StatusCode(StatusCodes.Status400BadRequest, apiresponse);
                return result;

            }
            catch (Exception ex)
            {
                APIResponse apiresponse = new APIResponse();
                apiresponse.Message = ex.Message;
                var result = StatusCode(StatusCodes.Status422UnprocessableEntity, apiresponse);
                return result;

            }

}

0 个答案:

没有答案