public async static Task <ILoginSession> LogonAsync(string jsonWebToken) { jsonWebToken.CheckArgument(nameof(jsonWebToken)); var result = default(LoginSession); if (JsonWebToken.CheckToken(jsonWebToken, out SecurityToken validatedToken)) { if (validatedToken.ValidTo < DateTime.UtcNow) { throw new LogicException(ErrorType.AuthorizationTimeOut); } var jwtValidatedToken = validatedToken as JwtSecurityToken; if (jwtValidatedToken != null) { var email = jwtValidatedToken.Claims.FirstOrDefault(e => e.Type == ClaimTypes.Email); if (email != null && email.Value != null) { using var identityCtrl = new Controllers.Persistence.Account.IdentityController(Factory.CreateContext()) { SessionToken = Authorization.SystemAuthorizationToken }; var identity = identityCtrl.ExecuteQuery(e => e.State == Contracts.Modules.Common.State.Active && e.EnableJwtAuth == true && e.Email.ToLower() == email.Value.ToString().ToLower()) .ToList() .FirstOrDefault(); if (identity != null) { var login = await QueryLoginAsync(identity.Email, identity.PasswordHash).ConfigureAwait(false); if (login != null) { result = new LoginSession(); result.CopyProperties(login); result.IsRemoteAuth = true; } } } } } else { throw new LogicException(ErrorType.InvalidJsonWebToken); } return(result ?? throw new LogicException(ErrorType.InvalidAccount)); }