示例#1
0
        public async Task SignUpUserConfirmation(ISignupConfirmModelUser confirmation)
        {
            try
            {
                ConfirmSignUpRequest confirmRequest = new ConfirmSignUpRequest()
                {
                    Username         = confirmation.Username,
                    ConfirmationCode = confirmation.ConfirmationCode,
                    ClientId         = GetClientId(),
                };

                AmazonCognitoIdentityProviderClient client = GetAmazonCognitoIdentity();
                ConfirmSignUpResponse confirmResult        = await client.ConfirmSignUpAsync(confirmRequest);
            }
            catch (CodeMismatchException e)
            {
                throw new WebApiException(System.Net.HttpStatusCode.Forbidden, e.Message);
            }
            catch (ExpiredCodeException e)
            {
                throw new WebApiException(System.Net.HttpStatusCode.Forbidden, e.Message);
            }
            catch (Exception e)
            {
                throw new WebApiException(System.Net.HttpStatusCode.InternalServerError, e.Message);
            }
        }
        public async Task <RequestResult> VerifyAccessCode(User user)
        {
            RequestResult        result = new RequestResult();
            ConfirmSignUpRequest confirmSignUpRequest = new ConfirmSignUpRequest();

            confirmSignUpRequest.Username         = user.Email;
            confirmSignUpRequest.ConfirmationCode = user.Code;
            confirmSignUpRequest.ClientId         = CLIENTAPP_ID;
            try
            {
                ConfirmSignUpResponse confirmSignUpResult = await provider.ConfirmSignUpAsync(confirmSignUpRequest);

                Console.WriteLine(confirmSignUpResult.ToString());
                result.Status  = true;
                result.Message = "User Verified Successfully. Please Sign In.";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
                Console.WriteLine(ex);
            }

            return(result);
        }
        public async Task <IActionResult> Confirm(User user)
        {
            var cognito = new AmazonCognitoIdentityProviderClient(_region);

            ConfirmSignUpRequest confirmRequest = new ConfirmSignUpRequest
            {
                Username         = user.Username,
                ClientId         = _appConfig.Value.AppClientId,
                ConfirmationCode = user.ConfirmationCode,
                //SecretHash = (username, configuration["cognito:clientId"], configuration["cognito:secretKey"])
            };

            await cognito.ConfirmSignUpAsync(confirmRequest);

            return(new OkObjectResult("Account has been confirmed"));
        }
        private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ConfirmSignUpRequest confirmRequest = new ConfirmSignUpRequest()
                {
                    Username         = UserNameTextBox.Text,
                    ClientId         = _clientId,
                    ConfirmationCode = ConfirmationTextBox.Text
                };

                var confirmResult = await _client.ConfirmSignUpAsync(confirmRequest);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                await new MessageDialog(message, "Sign Up Error").ShowAsync();
            }
        }
示例#5
0
        public async Task <CognitoContext> VerifyWithCode(string userName, string activationCode)
        {
            try
            {
                var result = await awsProvider.ConfirmSignUpAsync(new ConfirmSignUpRequest
                {
                    ClientId         = Keys.AWS_UsersPool_ClientID,
                    Username         = userName,
                    ConfirmationCode = activationCode
                });

                Debug.WriteLine("User verified success, navigate to sign in page");
                return(new CognitoContext(CognitoResult.Ok));
            }
            catch (Exception e)
            {
                Debug.WriteLine($"VerifyWithCode() threw an exception {e}");
                return(new CognitoContext(CognitoResult.Unknown, e.Message));
            }
        }
示例#6
0
        private async void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Amazon.CognitoIdentityProvider.Model.ConfirmSignUpRequest confirmSignUpRequest = new ConfirmSignUpRequest()
                {
                    Username         = txtEmail.Text,
                    ClientId         = _clientId,
                    ConfirmationCode = txtConfirm.Text
                };

                var confirmResult = await _client.ConfirmSignUpAsync(confirmSignUpRequest);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                var    msgBox  = new MessageDialog(message, "Sign Up Error");
                await msgBox.ShowAsync();
            }
        }
示例#7
0
        public async Task VerifyAccessCode(string username, string code)
        {
            try
            {
                AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), RegionEndpoint.EUCentral1);
                ConfirmSignUpRequest confirmSignUpRequest    = new ConfirmSignUpRequest();
                confirmSignUpRequest.Username         = username;
                confirmSignUpRequest.ConfirmationCode = code;
                confirmSignUpRequest.ClientId         = CLIENTAPP_ID;

                await provider.ConfirmSignUpAsync(confirmSignUpRequest);

                UserInfo.Verified = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("VerifyAccessCode ERROR: " + ex.Message);
                throw ex;
            }
        }
示例#8
0
        public override async Task <IdentityResult> ConfirmEmailAsync(string username, string code)
        {
            // Register the user using Cognito
            var confirmSignUpRequest = new ConfirmSignUpRequest
            {
                ClientId         = _clientId,
                ConfirmationCode = code,
                Username         = username
            };

            try
            {
                var result = await _client.ConfirmSignUpAsync(confirmSignUpRequest);

                return(IdentityResult.Success);
            }
            catch (Exception e)
            {
                return(IdentityResult.Failed(e.Message));
            }
        }
示例#9
0
        public async Task <CognitoContext> VerifyWithCode(string userName, string code)
        {
            try
            {
                var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.USWest2);

                var result = await provider.ConfirmSignUpAsync(new ConfirmSignUpRequest
                {
                    ClientId         = ClientId,
                    Username         = userName,
                    ConfirmationCode = code
                });

                return(new CognitoContext(CognitoResult.Ok));
            }
            catch (Exception e)
            {
                Console.WriteLine($"SignIn() threw an exception {e}");
            }
            return(new CognitoContext(CognitoResult.Unknown));
        }
示例#10
0
        /// <summary>
        /// Verify the access code to confirm signup when force password change is not imposed.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <bool> ConfirmSignUp(Real.ConfirmSignUpRequest request)
        {
            AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());
            ConfirmSignUpRequest confirmSignUpRequest    = new ConfirmSignUpRequest();

            confirmSignUpRequest.Username         = request.Username;
            confirmSignUpRequest.ConfirmationCode = request.TempCode;
            confirmSignUpRequest.ClientId         = CLIENTAPP_ID;
            try
            {
                ConfirmSignUpResponse confirmSignUpResult = await provider.ConfirmSignUpAsync(confirmSignUpRequest);

                Console.WriteLine(confirmSignUpResult.ToString());
            }
            catch (Exception ex)
            {
                ThrowCustomException(CognitoActionType.UserConfirmSignUp, ExceptionConstants.InternalServerErrorException, ex.StackTrace, ex.Message);
            }

            return(true);
        }
示例#11
0
        public override async Task Start(string _postJson, IDynamoDBContext _dynamoDBContext)
        {
            await base.Start(_postJson, _dynamoDBContext);

            User user          = JsonConvert.DeserializeObject <User>(_postJson);
            var  signUpRequest = new ConfirmSignUpRequest
            {
                ClientId         = ApiDefine.CognitoClientId,
                ConfirmationCode = user.Password,
                Username         = user.Name
            };


            var client = new AmazonCognitoIdentityProviderClient(ApiDefine.Credentials, RegionEndpoint.USWest2);
            var result = await client.ConfirmSignUpAsync(signUpRequest);

            JsPath = "cognito/confirm.js";
            string json = JsonConvert.SerializeObject(result);

            await loadJs();

            ExecJs = ExecJs.Replace("JSON", json.Replace("\"", "\\\""));
        }
示例#12
0
        public bool ConfirmSignup(UserConfirmRequest confirmRequest)
        {
            ConfirmSignUpRequest signUpRequest = new ConfirmSignUpRequest
            {
                ClientId         = _connectionInfo.ClientId,
                Username         = confirmRequest.Email,
                ConfirmationCode = confirmRequest.Code
            };

            try
            {
                ConfirmSignUpResponse response = _provider.ConfirmSignUpAsync(signUpRequest).Result;
                return(response.HttpStatusCode == HttpStatusCode.OK);
            }
            catch (AggregateException e)
            {
                if (e.InnerException != null)
                {
                    throw new UseCaseException()
                          {
                              UserErrorMessage = e.Message
                          }
                }
                ;

                throw new UseCaseException()
                      {
                          UserErrorMessage = e.Message, DevErrorMessage = e.ToString()
                      };
            }
            catch (Exception e)
            {
                LoggingHandler.LogError(e.Message);
                LoggingHandler.LogError(e.StackTrace);
                throw;
            }
        }
        public async Task <ConfirmSignUpResponse> ConfirmSignUpAsync(string username, string confirmationCode)
        {
            var client = new AmazonCognitoIdentityProviderClient(null, this.RegionEndpoint);
            ConfirmSignUpRequest confirmSignUpRequest = new ConfirmSignUpRequest();

            confirmSignUpRequest.Username         = username;
            confirmSignUpRequest.ConfirmationCode = confirmationCode;
            confirmSignUpRequest.ClientId         = this.ClientId;
            if (!string.IsNullOrEmpty(this.ClientSecret))
            {
                confirmSignUpRequest.SecretHash = CalculateSecretHash(this.ClientId, this.ClientSecret, username);
            }

            try
            {
                ConfirmSignUpResponse confirmSignUpResult = await client.ConfirmSignUpAsync(confirmSignUpRequest);

                return(confirmSignUpResult);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#14
0
        public async Task <Tuple <int, string> > ConfirmSignupAsync(string username, string code)
        {
            try
            {
                ConfirmSignUpRequest confirmRequest = new ConfirmSignUpRequest()
                {
                    Username         = username,
                    ClientId         = Constants.POOL_CLIENT_ID,
                    ConfirmationCode = code
                };

                var confirmResult = await client.ConfirmSignUpAsync(confirmRequest);

                if (confirmResult.HttpStatusCode == HttpStatusCode.OK)
                {
                    return(Tuple.Create <int, string>(1, "Confirmation request successfully!"));
                }
            }
            catch (Exception e)
            {
                return(Tuple.Create <int, string>(0, e.Message));
            }
            return(Tuple.Create <int, string>(-1, "Unable to confirm request!"));
        }
示例#15
0
        public virtual async Task <AuthEventEnum> VerifyCodeAsync(string code)
        {
            if (CurrentAuthProcess == AuthProcessEnum.None)
            {
                return(AuthEventEnum.Alert_NoActiveAuthProcess);
            }

            if (CurrentChallenge != AuthChallengeEnum.Code)
            {
                return(AuthEventEnum.Alert_VerifyCalledButNoChallengeFound);
            }

            try
            {
                switch (CurrentAuthProcess)
                {
                case AuthProcessEnum.None:
                    return(AuthEventEnum.Alert_InternalProcessError);

                case AuthProcessEnum.ResettingPassword:
                    await CognitoUser.ConfirmForgotPasswordAsync(code, newPassword).ConfigureAwait(false);

                    AuthChallengeList.Remove(AuthChallengeEnum.Code);
                    return(await NextChallenge());

                case AuthProcessEnum.SigningUp:
                    var result = await providerClient.ConfirmSignUpAsync(
                        new ConfirmSignUpRequest
                    {
                        ClientId         = clientId,
                        Username         = login,
                        ConfirmationCode = code
                    }).ConfigureAwait(false);

                    IsCodeVerified = true;
                    AuthChallengeList.Remove(AuthChallengeEnum.Code);
                    return(await NextChallenge());

                case AuthProcessEnum.SigningIn:
                    if (authFlowResponse == null)     // authFlowResponse set during VerifyPassword
                    {
                        return(AuthEventEnum.Alert_InternalSignInError);
                    }

                    authFlowResponse = await CognitoUser.RespondToSmsMfaAuthAsync(
                        new RespondToSmsMfaRequest()
                    {
                        SessionID = authFlowResponse.SessionID,
                        MfaCode   = code
                    }
                        ).ConfigureAwait(false);

                    AuthChallengeList.Remove(AuthChallengeEnum.Code);
                    return(await NextChallenge());

                case AuthProcessEnum.UpdatingEmail:
                    await CognitoUser.VerifyAttributeAsync("email", code).ConfigureAwait(false);

                    IsCodeVerified = true;
                    AuthChallengeList.Remove(AuthChallengeEnum.Code);
                    return(await NextChallenge());

                case AuthProcessEnum.UpdatingPhone:
                    return(AuthEventEnum.Alert_InternalProcessError);

                default:
                    return(AuthEventEnum.Alert_InternalProcessError);
                }
            }
            catch (InvalidPasswordException) { return(AuthEventEnum.Alert_PasswordFormatRequirementsFailed); }
            catch (TooManyRequestsException) { return(AuthEventEnum.Alert_TooManyAttempts); }
            catch (TooManyFailedAttemptsException) { return(AuthEventEnum.Alert_TooManyAttempts); }
            catch (NotAuthorizedException) { return(AuthEventEnum.Alert_NotAuthorized); }
            catch (UserNotFoundException) { return(AuthEventEnum.Alert_UserNotFound); }
            catch (UserNotConfirmedException) { return(AuthEventEnum.Alert_NotConfirmed); }
            catch (CodeMismatchException) { return(AuthEventEnum.Alert_VerifyFailed); }
            catch (AliasExistsException) { return(AuthEventEnum.Alert_AccountWithThatEmailAlreadyExists); }
            catch (Exception e)
            {
                Debug.WriteLine($"VerifyCode() threw an exception {e}");
                CognitoUser = null;
                return(AuthEventEnum.Alert_Unknown);
            }
        }