private async Task <bool> CheckPasswordAsync(string userName, string password)
        {
            try
            {
                var authReq = new AdminInitiateAuthRequest()
                {
                    UserPoolId = _poolId,
                    ClientId   = _clientId,
                    AuthFlow   = AuthFlowType.ADMIN_USER_PASSWORD_AUTH,
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

                // await new MessageDialog(authResp.ToString(), "Sign In Result").ShowAsync();
                return(true);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                await new MessageDialog(message, "Sign In Error").ShowAsync();
                return(false);
            }
        }
        public async Task <bool> CheckPasswordAsync(string userName, string password)
        {
            var userName1 = "*****@*****.**";
            var passwrod1 = "MytestPass141!asdfasdf";

            try
            {
                var authReq = new AdminInitiateAuthRequest
                {
                    UserPoolId = "us-east-1_0lir0CGDl",
                    ClientId   = "6aaambb1i02abdkokr2n4ohojl",
                    AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private async Task <string> CheckPasswordAsync(string userName, string password)
        {
            try
            {
                string accessKey = WebConfigurationManager.AppSettings["AWSAccessKeyId"];
                string secretKey = WebConfigurationManager.AppSettings["AWSSecretAccessKey"];
                //string _aWSRegion = ConfigurationManager.AppSettings["AWSRegion"];

                AmazonCognitoIdentityProviderClient _client = new AmazonCognitoIdentityProviderClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);
                var authReq = new AdminInitiateAuthRequest
                {
                    UserPoolId = WebConfigurationManager.AppSettings["USERPOOL_ID"],
                    ClientId   = WebConfigurationManager.AppSettings["CLIENT_ID"],
                    AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

                string IdToken = authResp.AuthenticationResult.IdToken;
                return(IdToken);
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }
        }
Esempio n. 4
0
        private async Task <bool> CheckPasswordAsync(string userName, string password)
        {
            try
            {
                var client = new AmazonCognitoIdentityProviderClient();

                var authReq = new AdminInitiateAuthRequest
                {
                    UserPoolId = ConfigurationManager.AppSettings["USERPOOL_ID"],
                    ClientId   = ConfigurationManager.AppSettings["CLIENT_ID"],
                    AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await client.AdminInitiateAuthAsync(authReq);

                // Validate that there is no case that an exception won't be thrown

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initiates the asynchronous ADMIN_NO_SRP_AUTH authentication flow
        /// </summary>
        /// <param name="adminAuthRequest">InitiateAdminNoSrpAuthRequest object containing the necessary
        /// parameters to initiate the ADMIN_NO_SRP_AUTH authentication flow</param>
        /// <returns>Returns the AuthFlowResponse object that can be used to respond to the next challenge,
        /// if one exists</returns>
        public void StartWithAdminNoSrpAuthAsync(InitiateAdminNoSrpAuthRequest adminAuthRequest, AsyncCallback <AuthFlowResponse> callback = null)
        {
            AdminInitiateAuthRequest initiateAuthRequest = CreateAdminAuthRequest(adminAuthRequest);

            Provider.AdminInitiateAuthAsync(initiateAuthRequest, r =>
            {
                if (r.Exception != null)
                {
                    callback?.Invoke(new AsyncResult <AuthFlowResponse>(null, r.Exception));
                    return;
                }

                AdminInitiateAuthResponse initiateResponse = r.Response;
                UpdateSessionIfAuthenticationComplete(initiateResponse.ChallengeName, initiateResponse.AuthenticationResult);

                callback?.Invoke(new AsyncResult <AuthFlowResponse>(new AuthFlowResponse()
                {
                    SessionID            = initiateResponse.Session,
                    ChallengeName        = initiateResponse.ChallengeName,
                    AuthenticationResult = initiateResponse.AuthenticationResult,
                    ChallengeParameters  = initiateResponse.ChallengeParameters,
                    ClientMetadata       = new Dictionary <string, string>(initiateResponse.ResponseMetadata.Metadata)
                }, null));
            });
        }
        public async Task <AuthResponse> LogIn(string username, string password)
        {
            try
            {
                var authReq = new AdminInitiateAuthRequest
                {
                    UserPoolId = Config.UserPoolId,
                    ClientId   = Config.ClientId,
                    AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH,
                };
                authReq.AuthParameters.Add("USERNAME", username);
                authReq.AuthParameters.Add("PASSWORD", password);
                //authReq.AuthParameters.Add("SECRET_HASH", AuthHelper.HashHmac(Config.UserPoolId, Config.ClientSecret));

                AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

                return(new AuthResponse
                {
                    AccessToken = authResp.AuthenticationResult.AccessToken,
                    ExpiresIn = authResp.AuthenticationResult.ExpiresIn,
                    IdToken = authResp.AuthenticationResult.IdToken,
                    RefreshToken = authResp.AuthenticationResult.RefreshToken,
                    TokenType = authResp.AuthenticationResult.TokenType,
                });
            }
            catch (Exception ex)
            {
                return(new AuthResponse
                {
                    ErrorMessage = ex.Message
                });
            }
        }
Esempio n. 7
0
    public static BooleanResult getResponse(String userName, String password)
    {
        try
        {
            var authReq = new AdminInitiateAuthRequest
            {
                UserPoolId = ConfigurationManager.AppSettings["USERPOOL_ID"],
                ClientId   = ConfigurationManager.AppSettings["CLIENT_ID"],
                AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
            };
            authReq.AuthParameters.Add("USERNAME", userName);
            authReq.AuthParameters.Add("PASSWORD", password);

            AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

            return(new BooleanResult()
            {
                Success = true
            });
        }
        catch
        {
            return(new BooleanResult()
            {
                Success = false
            });
        }
    }
Esempio n. 8
0
        public async Task <string> GetIdFromRefresh(string refreshToken)
        {
            var authReq = new AdminInitiateAuthRequest
            {
                UserPoolId = userPoolId,
                ClientId   = clientId,
                AuthFlow   = AuthFlowType.REFRESH_TOKEN_AUTH
            };

            AdminInitiateAuthResponse authResp = await new AmazonCognitoIdentityProviderClient().AdminInitiateAuthAsync(authReq);

            return(authResp.AuthenticationResult.IdToken);
        }
        /// <summary>
        /// Initiates the asynchronous ADMIN_NO_SRP_AUTH authentication flow
        /// </summary>
        /// <param name="adminAuthRequest">InitiateAdminNoSrpAuthRequest object containing the necessary
        /// parameters to initiate the ADMIN_NO_SRP_AUTH authentication flow</param>
        /// <returns>Returns the AuthFlowResponse object that can be used to respond to the next challenge,
        /// if one exists</returns>
        public async Task <AuthFlowResponse> StartWithAdminNoSrpAuthAsync(InitiateAdminNoSrpAuthRequest adminAuthRequest)
        {
            AdminInitiateAuthRequest initiateAuthRequest = CreateAdminAuthRequest(adminAuthRequest);

            AdminInitiateAuthResponse initiateResponse =
                await Provider.AdminInitiateAuthAsync(initiateAuthRequest).ConfigureAwait(false);

            UpdateSessionIfAuthenticationComplete(initiateResponse.ChallengeName, initiateResponse.AuthenticationResult);

            return(new AuthFlowResponse(initiateResponse.Session,
                                        initiateResponse.AuthenticationResult,
                                        initiateResponse.ChallengeName,
                                        initiateResponse.ChallengeParameters,
                                        new Dictionary <string, string>(initiateResponse.ResponseMetadata.Metadata)));
        }
Esempio n. 10
0
        private static AdminInitiateAuthResponse GenerateAuthResponse()
        {
            var authResult = new AuthenticationResultType
            {
                AccessToken  = "test-token",
                ExpiresIn    = 123,
                IdToken      = "test-token",
                RefreshToken = "test-token"
            };
            var token = new AdminInitiateAuthResponse
            {
                AuthenticationResult = authResult
            };

            return(token);
        }
Esempio n. 11
0
        public override async Task Start(string _postJson, IDynamoDBContext _dynamoDBContext)
        {
            await base.Start(_postJson, _dynamoDBContext);

            User user = JsonConvert.DeserializeObject <User>(_postJson);


            var authReq = new AdminInitiateAuthRequest()
            {
                UserPoolId = ApiDefine.CognitoPoolId,
                ClientId   = ApiDefine.CognitoClientId,
                AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
            };

            authReq.AuthParameters.Add("USERNAME", user.Email);
            authReq.AuthParameters.Add("EMAIL", user.Email);
            authReq.AuthParameters.Add("PASSWORD", user.Password);

            var client = new AmazonCognitoIdentityProviderClient(ApiDefine.Credentials, RegionEndpoint.USWest2);
            AdminInitiateAuthResponse authResp = await client.AdminInitiateAuthAsync(authReq);

            // AccessTokenを元にUser名を取得
            var getUserReq = new GetUserRequest()
            {
                AccessToken = authResp.AuthenticationResult.AccessToken
            };

            var getUserResp = await client.GetUserAsync(getUserReq);

            /*var req = new AdminRespondToAuthChallengeRequest()
             * {
             *  ChallengeName = ChallengeNameType.ADMIN_NO_SRP_AUTH,
             *  ClientId = ApiDefine.CognitoClientId,
             *  UserPoolId = ApiDefine.CognitoPoolId,
             *  Session = authResp.Session,
             *  ChallengeResponses = new Dictionary<string, string>() {
             *      { "USERNAME", user.Email }, { "PASSWORD", user.Password }
             *  },
             * };
             * var resp =  await client.AdminRespondToAuthChallengeAsync(req);*/
            JsPath = "cognito/my.page.js";
            string json = JsonConvert.SerializeObject(getUserResp);

            await loadJs();

            ExecJs = ExecJs.Replace("_JSON", json.Replace("\"", "\\\""));
        }
Esempio n. 12
0
        public async Task <AdminInitiateAuthResponse> PerformAuthAsync(UserForCreationDto user)
        {
            var authRequest = new AdminInitiateAuthRequest
            {
                UserPoolId = _settings.Value.UserPoolId,
                ClientId   = _settings.Value.UserPoolClientId,
                AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
            };

            authRequest.AuthParameters.Add("USERNAME", user.UserName);
            authRequest.AuthParameters.Add("PASSWORD", user.Password);

            AmazonCognitoIdentityProviderClient _client = new AmazonCognitoIdentityProviderClient();

            AdminInitiateAuthResponse authResponse = await _client.AdminInitiateAuthAsync(authRequest);

            return(authResponse);
        }
        private async Task <bool> CheckPasswordAsync(string userName, string password)
        {
            try
            {
                var authReq = new AdminInitiateAuthRequest
                {
                    UserPoolId = ConfigurationManager.AppSettings["USERPOOL_ID"],
                    ClientId   = ConfigurationManager.AppSettings["CLIENT_ID"],
                    AuthFlow   = AuthFlowType.ADMIN_NO_SRP_AUTH
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await _client.AdminInitiateAuthAsync(authReq);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            AdminInitiateAuthResponse response = new AdminInitiateAuthResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("AuthenticationResult", targetDepth))
                {
                    var unmarshaller = AuthenticationResultTypeUnmarshaller.Instance;
                    response.AuthenticationResult = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ChallengeName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ChallengeName = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ChallengeParameters", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.ChallengeParameters = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Session", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Session = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Esempio n. 15
0
        private async Task <bool> CheckPasswordAsync(string userName, string password)
        {
            try
            {
                var authReq = new AdminInitiateAuthRequest()
                {
                    UserPoolId = COGNITO_USRE_POOL_ID,
                    ClientId   = COGNITO_CLIENT_ID,
                    AuthFlow   = AuthFlowType.ADMIN_USER_PASSWORD_AUTH,
                };
                authReq.AuthParameters.Add("USERNAME", userName);
                authReq.AuthParameters.Add("PASSWORD", password);

                AdminInitiateAuthResponse authResp = await AwsCognitoIdentityProviderClient.AdminInitiateAuthAsync(authReq);

                return(true);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                await new MessageDialog(message, "Sign In Error").ShowAsync();
                return(false);
            }
        }
Esempio n. 16
0
        public async Task <ISigninModelResponse> SignInUser(ISigninModelUser user)
        {
            AdminInitiateAuthResponse authResponse = await TrySignInUser(user);

            return(new SigninResponse(authResponse));
        }