public AuthenticationCreateUserTests() : base() { AdminCreateUserRequest createUserRequest = new AdminCreateUserRequest() { TemporaryPassword = "******", Username = "******", UserAttributes = new List <AttributeType>() { new AttributeType() { Name = CognitoConstants.UserAttrEmail, Value = "*****@*****.**" }, }, ValidationData = new List <AttributeType>() { new AttributeType() { Name = CognitoConstants.UserAttrEmail, Value = "*****@*****.**" } }, UserPoolId = pool.PoolID }; AdminCreateUserResponse createReponse = provider.AdminCreateUserAsync(createUserRequest).Result; user = new CognitoUser("User5", pool.ClientID, pool, provider); }
/// <summary> /// This send the temporary code again to the admin created user which is now not activate /// </summary> /// <param name="username"></param> /// <returns></returns> public async Task <bool> ResendTemporaryPasssword(Real.ResendTemporaryCodeRequest request) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(RegionEndpoint.GetBySystemName(REGION)); AdminCreateUserRequest userRequest = new AdminCreateUserRequest(); userRequest.Username = request.Username; userRequest.UserPoolId = POOL_ID; userRequest.DesiredDeliveryMediums = new List <string>() { "EMAIL" }; userRequest.MessageAction = MessageActionType.RESEND; userRequest.TemporaryPassword = PasswordGenerator.GeneratePassword(true, true, true, true, false, 6); try { AdminCreateUserResponse response = await provider.AdminCreateUserAsync(userRequest); } catch (Exception e) { Console.WriteLine(e); return(false); } return(true); }
public async Task <Guid> CreateAsync(Profile profile) { var request = CreateUser(profile); AdminCreateUserResponse result = null; try { result = await _provider.AdminCreateUserAsync(request); } catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); } return(Guid.Parse(result.User.Attributes.FirstOrDefault(a => a.Name == "sub").Value)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { AdminCreateUserResponse response = new AdminCreateUserResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("User", targetDepth)) { var unmarshaller = UserTypeUnmarshaller.Instance; response.User = unmarshaller.Unmarshall(context); continue; } } return(response); }
/// <summary> /// Used to Create User in cognito. other attributes can be provided but are not mandatory. /// </summary> /// <param name="username"></param> /// <param name="email"></param> /// <param name="phoneNumber"></param> /// <returns></returns> public async Task <AdminCreateUserResponse> AdminCreateUserAsync(Real.AdminCreateUserRequest request) { AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(RegionEndpoint.GetBySystemName(REGION)); AWSModels.AdminCreateUserRequest userRequest = new AWSModels.AdminCreateUserRequest(); userRequest.Username = request.Username; userRequest.UserPoolId = POOL_ID; userRequest.DesiredDeliveryMediums = new List <string>() { "EMAIL" }; userRequest.TemporaryPassword = PasswordGenerator.GeneratePassword(true, true, true, true, false, 6); userRequest.UserAttributes.Add(new AttributeType { Name = "email", Value = request.Email }); userRequest.UserAttributes.Add(new AttributeType { Name = "phone_number", Value = request.PhoneNumber }); AdminCreateUserResponse response = null; try { response = await provider.AdminCreateUserAsync(userRequest); } catch (CodeDeliveryFailureException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.CodeDeliveryFailureException, ex.StackTrace, ex.Message); } catch (InternalErrorException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.InternalErrorException, ex.StackTrace, ex.Message); } catch (InvalidLambdaResponseException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.InvalidLambdaResponseException, ex.StackTrace, ex.Message); } catch (InvalidParameterException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.InvalidParameterException, ex.StackTrace, ex.Message); } catch (InvalidUserPoolConfigurationException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.InvalidUserPoolConfigurationException, ex.StackTrace, ex.Message); } catch (PasswordResetRequiredException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.PasswordResetRequiredException, ex.StackTrace, ex.Message); } catch (ResourceNotFoundException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.ResourceNotFoundException, ex.StackTrace, ex.Message); } catch (TooManyRequestsException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.TooManyRequestsException, ex.StackTrace, ex.Message); } catch (UnexpectedLambdaException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UnexpectedLambdaException, ex.StackTrace, ex.Message); } catch (UserLambdaValidationException ex) { if (ex.Message == "User account already exists") { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UserNameExistsException, ex.StackTrace, ex.Message); } ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UserLambdaValidationException, ex.StackTrace, ex.Message); } catch (UserNotConfirmedException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UserNotConfirmedException, ex.StackTrace, ex.Message); } catch (UserNotFoundException ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UserNotFoundException, ex.StackTrace, ex.Message); } catch (AmazonCognitoIdentityProviderException ex) { if (ex.Message == "User account already exists") { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.UserNameExistsException, ex.StackTrace, ex.Message); } ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.AmazonCognitoIdentityProviderException, ex.StackTrace, ex.Message); } catch (Exception ex) { ThrowCustomException(CognitoActionType.AdminCreateUser, ExceptionConstants.ErrorException, ex.StackTrace, ex.Message); } return(response); }