protected UserToken(string userId, string userName, string role, string profileId, ConsumerKey consumerKey,
                     string tokenId, string jwtIssuer)
 {
     UserName    = userName;
     Role        = GetRoleFromString(role);
     ConsumerKey = consumerKey;
     UserID      = userId;
     ProfileID   = profileId;
     TokenID     = tokenId;
     JwtIssuer   = jwtIssuer;
     SetExpiryTime();
     SetScope();
 }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (JwtIssuer != null ? JwtIssuer.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UserName != null ? UserName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UserID != null ? UserID.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ProfileID != null ? ProfileID.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TokenID != null ? TokenID.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ConsumerKey != null ? ConsumerKey.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Scope;
         hashCode = (hashCode * 397) ^ (int)Role;
         return(hashCode);
     }
 }
        public static RefreshToken FromJWT(string tokenString, ConsumerKey consumerKey, string issuer, string secretKey)
        {
            var decodedToken = FromJWT(tokenString, secretKey);

            if (decodedToken == null || !string.Equals(decodedToken["consumerKey"].ToString(), consumerKey.Value) ||
                !string.Equals(decodedToken["scope"].ToString(), TokenScope.REFRESH.ToString()) ||
                !string.Equals(decodedToken["iss"].ToString(), issuer))
            {
                throw new UnauthorizedException("Refresh token passed is not valid!");
            }
            decodedToken["consumerKey"] = consumerKey;
            var refreshToken = new RefreshToken(decodedToken);

            if (IsExpired(refreshToken.ExpiryTime))
            {
                var epoch      = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                var expiryTime = epoch.AddSeconds(long.Parse(decodedToken["exp"].ToString()));
                refreshToken.ExpiryTime = expiryTime;
            }
            return(refreshToken);
        }
 public RefreshToken(string userId, string profileId, string userName, string role, ConsumerKey consumerKey,
                     string tokenId, string issuer)
     : base(userId, userName, role, profileId, consumerKey, tokenId, issuer)
 {
 }
 protected bool Equals(ConsumerKey other)
 {
     return(Equals(Id, other.Id) && string.Equals(Value, other.Value) && string.Equals(Channel, other.Channel));
 }