public JwTokenOutputDto PerformAuthentication(CredentialInputDto credential)
        {
            var identityUser = _unitOfWork.IdentityUsers.GetByUserName(credential.UserName);

            Notification notification = Validation(credential);

            if (notification.HasErrors())
            {
                throw new ArgumentException(notification.ErrorMessage());
            }

            string accessToken = _identityUserDomainService.PerformAuthentication(identityUser, credential.UserName,
                                                                                  credential.Password, _config["Jwt:Key"], _config["Jwt:Issuer"]);

            return(new JwTokenOutputDto {
                access_token = accessToken
            });
        }
        private Notification Validation(CredentialInputDto credential)
        {
            Notification notification = new Notification();

            if (credential == null)
            {
                notification.AddError("Invalid JSON data in request body.");
                return(notification);
            }

            if (string.IsNullOrEmpty(credential.UserName))
            {
                notification.AddError("UserName is missing");
            }

            if (string.IsNullOrEmpty(credential.Password))
            {
                notification.AddError("Password is missing");
            }

            return(notification);
        }
Example #3
0
 public IActionResult Login([FromBody] CredentialInputDto credential)
 {
     return(Ok(_identityUserApplicationService.PerformAuthentication(credential)));
 }