public async Task <AuthResult <Token> > RefreshToken(RefreshTokenDTO refreshTokenDto) { var refreshToken = refreshTokenDto?.Token?.Refresh_token; if (string.IsNullOrEmpty(refreshToken)) { return(AuthResult <Token> .UnvalidatedResult); } try { var principal = jwtManager.GetPrincipal(refreshToken, isAccessToken: false); int.TryParse(principal.Identity.GetUserId(), out var currentUserId); var user = await userManager.FindByIdAsync(currentUserId); if (user != null && user.Id > 0 && !user.IsDeleted) { var token = jwtManager.GenerateToken(user); return(AuthResult <Token> .TokenResult(token)); } } catch (Exception) { return(AuthResult <Token> .UnauthorizedResult); } return(AuthResult <Token> .UnauthorizedResult); }
private bool ValidateToken(string token, out string machineSerial) { machineSerial = null; var simplePrinciple = JwtManager.GetPrincipal(token); if (simplePrinciple == null) { return(false); } var identity = simplePrinciple.Identity as ClaimsIdentity; if (identity == null) { return(false); } if (!identity.IsAuthenticated) { return(false); } var machineSerialClaim = identity.FindFirst(ClaimTypes.Name); machineSerial = machineSerialClaim?.Value; if (string.IsNullOrEmpty(machineSerial)) { return(false); } var exp = simplePrinciple.FindFirst("exp"); // More validate to check whether machineSerial exists in system return(true); }