コード例 #1
0
        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);
        }
コード例 #2
0
        public ApiIdentityResult VerifyToken(string token, String attributeName)
        {
            ApiIdentityResult ret = new ApiIdentityResult();

            try
            {
                var request = new GetUserAttributeVerificationCodeRequest()
                {
                    AccessToken   = token,
                    AttributeName = attributeName
                };

                using var provider = GetCognitoIdentityProvider();
                var response = provider.GetUserAttributeVerificationCodeAsync(request).GetAwaiter().GetResult();
                if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    ret.SetFailed(-100, response.ResponseMetadata.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ret.SetFailed(-101, ex.Message);
            }

            return(ret);
        }