Exemplo n.º 1
0
        public static async Task ResetPwdForgot(string _username, string _code, int _clientid, string _newPassword)
        {
            using (var cognito = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Constants.REGION))
            {
                ConfirmForgotPasswordRequest confirmForgotPasswordRequest = new ConfirmForgotPasswordRequest()
                {
                    Username         = _username,
                    ClientId         = Constants.CLIENTAPP_ID,
                    Password         = _newPassword,
                    SecretHash       = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret),
                    ConfirmationCode = _code
                };

                ConfirmForgotPasswordResponse confirmForgotPasswordResponse = new ConfirmForgotPasswordResponse();

                try
                {
                    confirmForgotPasswordResponse = await cognito.ConfirmForgotPasswordAsync(confirmForgotPasswordRequest).ConfigureAwait(false);

                    ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CONFIRMED);
                }
                catch (CodeMismatchException)
                {
                    // Username Unknown or Code Expired
                    ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_MISMATCH_KO);
                }
                catch (ExpiredCodeException)
                {
                    // Username Unknown or Code Expired
                    ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_EXPIRED_KO);
                }
                catch (Exception e)
                {
                    HandleForgotPwdExceptions(e, _clientid);
                }
            }



            // Initiate Forgot Password Modification By Code

            /*try
             * {
             *  // Lunch myUser Change Forgotten Pwd
             *  //await Server.clients[_clientid].myUser.ConfirmForgotPasswordAsync(_code, _newPassword);
             *  await Server.cognitoManagerServer.provider.
             *  ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CONFIRMED);
             *
             *  // Authenticate & Check Challenge.
             *
             * }
             * catch (Exception e)
             * {
             *  HandleExceptions(e, _clientid, Constants.SCENE_FORGOT_PASSWORD);
             * }*/
        }
Exemplo n.º 2
0
        public static async Task ClientForgotPwdRequest(string _username, int _clientid)
        {
            using (var cognito = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Constants.REGION))
            {
                ForgotPasswordRequest ForgotPasswordRequest = new ForgotPasswordRequest()
                {
                    Username   = _username,
                    ClientId   = Constants.CLIENTAPP_ID,
                    SecretHash = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret),
                };

                ForgotPasswordResponse ForgotPasswordResponse = new ForgotPasswordResponse();

                try
                {
                    Console.WriteLine("SignInClients.cs | ForgotPasswordAsync Sending");
                    ForgotPasswordResponse = await cognito.ForgotPasswordAsync(ForgotPasswordRequest).ConfigureAwait(false);

                    Console.WriteLine("SignInClients.cs | ForgotPasswordAsync OK");
                    ServerSend.ClientForgotPasswordStatus(_clientid, Constants.NEW_CODE_SEND_EMAIL);
                }
                catch (ExpiredCodeException)
                {
                    // Username Unknown or Code Expired
                    ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_CODE_EXPIRED_KO);
                }
                catch (Exception e)
                {
                    Console.WriteLine("SignInClients.cs | My User ClientForgotPwdRequest Failed");
                    switch (e.GetType().ToString())
                    {
                    default:
                        Console.WriteLine("SignInClients.cs | Unknown Exception | " + e.GetType().ToString() + " | " + e);
                        //ServerSend.ClientForgotPasswordStatus(_clientid, Constants.FORGOT_PASSWORD_KO);
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async void SignUptoCognito(int _clientid, string _username, string _password, string _email)
        {
            // If the REgEx Formats are Respected, we proceed to Adhesion OR We Return an Error Format
            if (SecurityCheck.CheckUserPattern(_username))
            {
                if (SecurityCheck.CheckPasswordPattern(_password))
                {
                    if (SecurityCheck.CheckEmailPattern(_email))
                    {
                        SignUpRequest signUpRequest = new SignUpRequest()
                        {
                            ClientId   = Constants.CLIENTAPP_ID,
                            Username   = _username,
                            Password   = _password,
                            SecretHash = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret)
                        };

                        List <AttributeType> attributes = new List <AttributeType>()
                        {
                            new AttributeType()
                            {
                                Name = "email", Value = _email
                            }
                        };

                        // Send SignupRequest
                        signUpRequest.UserAttributes = attributes;

                        try
                        {
                            SignUpResponse result = await Server.cognitoManagerServer.provider.SignUpAsync(signUpRequest);

                            if (result.HttpStatusCode == System.Net.HttpStatusCode.OK)
                            {
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_OK);
                            }
                        }
                        catch (Exception e)
                        {
                            switch (e.GetType().ToString())
                            {
                            case "Amazon.CognitoIdentityProvider.Model.UsernameExistsException":
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_ALREADY_EXIST);
                                break;

                            default:
                                NlogClass.target.WriteAsyncLogEvent(new AsyncLogEventInfo(new LogEventInfo(LogLevel.Error, "SignUpClientToCognito", "Client ID : " + _clientid.ToString() + "  | New Exception | Code : " + e.GetType().ToString() + " | Exeption : " + e.Message), NlogClass.exceptions.Add));
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_KO);
                                break;
                            }
                        }
                    }
                    else
                    {
                        ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_EMAIL_KO);
                    }
                }
                else
                {
                    ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_PASSWORD_KO);
                }
            }
            else
            {
                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_USERNAME_KO);
            }
        }