public TokenResponseModel RenewAccessToken(RenewTokenInputType renewToken) { var result = new TokenResponseModel { Message = "Success" }; ClaimsPrincipal principal = GetClaimsFromExpiredToken(renewToken.AccessToken); if (principal == null) { result.Message = "Invalid Token"; return(result); } string email = principal.Claims.Where(_ => _.Type == "Email").Select(_ => _.Value).FirstOrDefault(); if (string.IsNullOrEmpty(email)) { result.Message = "Invalid Token"; return(result); } var user = _authContext.User .Where(_ => _.EmailAddress == email && _.RefreshToken == renewToken.RefreshToken && _.RefershTokenExpiration > DateTime.Now).FirstOrDefault(); if (user == null) { result.Message = "Invalid Token"; return(result); } var userRoles = _authContext.UserRoles.Where(_ => _.UserId == user.UserId).ToList(); result.AccessToken = GetJWTAuthKey(user, userRoles); result.RefreshToken = GenerateRefreshToken(); user.RefreshToken = result.RefreshToken; user.RefershTokenExpiration = DateTime.Now.AddDays(7); _authContext.SaveChanges(); return(result); }
public TokenResponseModel RenewAccessToken([Service] IAuthLogic authLogic, RenewTokenInputType renewToken) { return(authLogic.RenewAccessToken(renewToken)); }