创建账户状态为“ CONFIRMED”且没有电子邮件地址的AWS Cognito用户

时间:2019-09-09 04:50:13

标签: c# aws-sdk amazon-cognito

如何创建使用C#确认帐户状态的Cognito用户?创建用户后,帐户状态显示为FORCE_CHANGE_PASSWORD。另一件事是我需要创建没有电子邮件地址的用户。

 AmazonCognitoIdentityProviderClient cognitoProvider = 
            new AmazonCognitoIdentityProviderClient(region);

 string userName = "user";
 string tempPassword = "Temp@3434";
 string newPassword = "RealPass@2019";

 AdminCreateUserRequest adminUserCreateRequest = new AdminCreateUserRequest()
 {
     UserPoolId = poolId,
     Username = userName,
     TemporaryPassword = tempPassword 
 };

 AdminCreateUserResponse signUpResponse = await cognitoProvider.AdminCreateUserAsync(adminUserCreateRequest);

管理员InitiateRequest

 Dictionary<string, string> initialParams = new Dictionary<string, string>();
        initialParams.Add("USERNAME", userName);
        initialParams.Add("PASSWORD", tempPassword);

        AdminInitiateAuthRequest initialRequest = new AdminInitiateAuthRequest()
        {
            AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH,
            AuthParameters = initialParams,
            ClientId = appClientId_tenantApi,
            UserPoolId = poolId                
        };

        AdminInitiateAuthResponse resInitAuth = await cognitoProvider.AdminInitiateAuthAsync(initialRequest);

InitiateAuthRresponse将电子邮件作为必填属性。 {[requiredAttributes,[“ userAttributes.email”]]}

但是文档没有这么说。

对于ADMIN_NO_SRP_AUTH:USERNAME(必填),SECRET_HASH(如果应用客户端配置了客户端密码),PASSWORD(必填),DEVICE_KEY

管理员回应挑战

 var authParameters = new Dictionary<string, string>();
            authParameters.Add("USERNAME", userName);
            authParameters.Add("NEW_PASSWORD", newPassword);

        AdminRespondToAuthChallengeRequest adminAuthRequest = new AdminRespondToAuthChallengeRequest()
        {
            UserPoolId = poolId,
            ClientId = appClientId_tenantApi,
            ChallengeName = ChallengeNameType.NEW_PASSWORD_REQUIRED,
            ChallengeResponses = authParameters,
            Session = session
            };

cognitoProvider.AdminRespondToAuthChallengeAsync(adminAuthRequest);

我认为我可能会错过Cognito中的某些用户设置以避免电子邮件发送。有没有类似的经历?还是无法创建没有电子邮件的用户?

1 个答案:

答案 0 :(得分:1)

  1. 在用户池的创建过程中,按常规设置;具有照片中的属性cognito creation on aws,需要选择必须显示的属性,我认为您选择的电子邮件是由默认,因此您收到了质询请求响应。

  2. 管理员创建用户请求要求客户端确认电子邮件,以验证用户是否拥有电子邮件。

  3. 同样的方法是允许用户在您的cognito配置上进行注册,然后注册某人,然后输入用户名和密码,然后继续确认他们为管理员

    var signup = await cognitoClient.SignUpAsync(new SignUpRequest
    {
        Username = person.Username,
        ClientId = cognitoOptions.ClientId,
        Password = person.IdNumber,
    });
    
     var confirm = await cognitoClient.AdminConfirmSignUpAsync(new AdminConfirmSignUpRequest
    {
        Username = person.Username,
        UserPoolId = cognitoOptions.UserPoolId
    });