【问题标题】:How to delete a Pool user in AWS Cognito and C#?如何在 AWS Cognito 和 C# 中删除池用户?
【发布时间】:2022-07-19 14:16:50
【问题描述】:

我在 C# 和 Android 中使用了名为 aws-cognito-dot-net-desktop-app 的 aws-samples 示例:

aws-cognito-dot-net-desktop-app

它运行良好,并且在 Cognito 中正确注册了用户。

要注册用户,请执行以下操作:

bool success = await helper.SignUpUser(etUserName.Text, etPasswordUser.Text, etEmailUser.Text, etPhoneUser.Text);

通过这种方式创建用户,但需要输入发送到用户电子邮件的代码。代码入口如下:

CognitoHelper cognitoHelper = new CognitoHelper();
return await cognitoHelper.VerifyAccessCode(userName, codeSentToMail);

并且用户注册没有问题,也就是说,它工作正常:

现在我想删除任何创建的用户,我正在为其创建一个任务,如下所示:

internal async Task<bool> DeleteUser(string username)
{
   try
   {
      AmazonCognitoIdentityProviderClient provider =
        new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), RegionEndpoint.USEast1);            

      DeleteUserPoolRequest request = new DeleteUserPoolRequest();
      request.UserPoolId = username;
      DeleteUserPoolResponse deleteUserPoolClientResponse = await provider.DeleteUserPoolAsync(request);
      return true;
    }
    catch (Exception ex)
    {
       Console.WriteLine(ex);
       return false;
    }
}

执行 DeleteUserPoolRequest 时,会引发异常,指示 Amazon.Runtime.ErrorType.Unknown 类型的错误

知道我做错了什么吗?

欢迎任何cmets或建议。

【问题讨论】:

    标签: c# amazon-web-services amazon-cognito


    【解决方案1】:

    公共静态异步任务 DeleteUserFromAws(string emailId) { 尝试 { AmazonCognitoIdentityProviderClient 认知 = 新的 AmazonCognitoIdentityProviderClient(awsAccessKeyId, awsSecretAccessKey, Region1); CognitoUserPool cognitoUserPool = new CognitoUserPool(poolId, appClienId, cognito); AdminGetUserRequest adminGetUserRequest = new AdminGetUserRequest(); adminGetUserRequest.Username = emailId; adminGetUserRequest.UserPoolId = poolId; AdminGetUserResponse adminGetUserResponse = 等待 cognito.AdminGetUserAsync(adminGetUserRequest); var getUserNameByEmaliID = adminGetUserResponse.Username;

                AmazonCognitoIdentityProviderClient provider =
                  new AmazonCognitoIdentityProviderClient(awsAccessKeyId, awsSecretAccessKey, Region1);
                AdminDeleteUserRequest request = new AdminDeleteUserRequest();
                CancellationToken cancellationToken = default;
                request.Username = getUserNameByEmaliID;
                request.UserPoolId = poolId;
                await provider.AdminDeleteUserAsync(request,cancellationToken);
                return true;
            }
            catch (Exception ex)
            {
                Logger.log(ex, (Int32)Category.Fatal, (Int32)Priority.High);
                throw;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2020-06-16
      • 2018-11-07
      • 2023-03-29
      • 1970-01-01
      • 2016-12-29
      • 2018-05-16
      • 2019-10-06
      • 2021-10-05
      • 2018-01-31
      相关资源
      最近更新 更多