public static SessionDto GetSession(this HttpRequest req, ITokenService tokenService, string key) { var session = new SessionDto(); try { session.UserId = getValue(req, "UserId"); session.Expires = long.Parse(getValue(req, "Expires")); session.Token = getValue(req, "Token"); } catch { } if (!tokenService.ValidateToken(session.Token, session, key)) { throw new UnauthorizedAccessException(); } return(session); }
public static string CreateToken(this ITokenService tokenService, SessionDto session, string key) { var value = getValue(session); return(tokenService.CreateToken(value, key, "")); }
private static string getValue(SessionDto session) { return($"<{ session.UserId }><{session.Expires:yyyy-MM-dd hh:mm:ss}>"); }
public static bool ValidateToken(this ITokenService tokenService, string token, SessionDto session, string key) { var value = getValue(session); return(tokenService.ValidateToken(token, value, key, "")); }