public bool Authenticate(out UserInfo user, string username, string password = "")
 {
     if (!string.IsNullOrWhiteSpace(password))
     {
         // Authenticate user login here.
         user = _user.GetUserInfo(username, password);
         if (user != null)
         {
             return true;
         }
     }
     user = null;
     return false;
 }
 public static Token CreateToken(UserInfo user, string perms)
 {
     var claims = new List<Claim>()
         {
             new Claim(ClaimTypes.UserData, user.UserId.ToString()),
             new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()),
             new Claim(ClaimTypes.Sid, user.UserId.ToString()),
             new Claim(ClaimTypes.Name, user.FullName.ToString())
         };
     var key = new InMemorySymmetricSecurityKey(TokenConstants.TokenKey);
     var jwt = new JwtSecurityTokenHandler() { TokenLifetimeInMinutes = TokenConstants.TokenLifetimeInMinutes };
     var token = jwt.CreateToken(CreateSecurityTokenDescriptor(claims, key));
    
     return new Token() { Value = jwt.WriteToken(token), Expiry = TokenConstants.TokenLifetimeInMinutes, User = user.FullName, Perms = perms };
 }