Exemplo n.º 1
0
        public async Task <IActionResult> LoginUser([FromBody] UserToLoginRequest user, CancellationToken cancellationToken)
        {
            var command = new LoginUserCommand
            {
                User = user
            };

            var loggedUser = await _mediator.Send(command, cancellationToken);

            return(Ok(loggedUser));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login(UserToLoginRequest userToLoginRequest)
        {
            try
            {
                CognitoUserPool  userPool = new CognitoUserPool(_config.GetSection("AWS").GetSection("UserPoolId").Value, _config.GetSection("AWS").GetSection("UserPoolClientId").Value, _cognitoIdentityProvider);
                CognitoUser      user     = new CognitoUser(userToLoginRequest.Email, _config.GetSection("AWS").GetSection("UserPoolClientId").Value, userPool, _cognitoIdentityProvider);
                AuthFlowResponse context  = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest
                {
                    Password = userToLoginRequest.Password
                }).ConfigureAwait(false);

                return(Ok(new CommonResponse(ErrorCodes.USER_NOT_CONFIRMED, string.Empty, context.AuthenticationResult.AccessToken)));
            }
            catch (AmazonServiceException e)
            {
                switch (e.ErrorCode)
                {
                case "UserNotConfirmedException":
                    return(Ok(new CommonResponse(ErrorCodes.USER_NOT_CONFIRMED, e.Message)));
                }
                return(BadRequest(new CommonResponse(ErrorCodes.ERROR, e.Message)));
            }
        }