public bool setClaim(string key, string value, Error error)
 {
     if (RegisteredClaimUtils.exists(key))
     {
         return(base.setClaim(key, value, error));
     }
     else
     {
         error.setError("RC001", "Wrong registered key value");
         return(false);
     }
 }
 public override object getClaimValue(string key, Error error)
 {
     if (RegisteredClaimUtils.exists(key))
     {
         for (int i = 0; i < _claims.Count; i++)
         {
             if (SecurityUtils.compareStrings(key, _claims[i].getKey()))
             {
                 return(_claims[i].getValue());
             }
         }
         error.setError("RC001", "Could not find a claim with" + key + " key value");
         return("");
     }
     else
     {
         error.setError("RC002", "Wrong registered key value");
         return("");
     }
 }
 public bool setTimeValidatingClaim(string key, string value, string customValidationSeconds, Error error)
 {
     if (RegisteredClaimUtils.exists(key) && RegisteredClaimUtils.isTimeValidatingClaim(key))
     {
         Int32 date = 0;
         customTimeValidationClaims.Add(key, customValidationSeconds);
         try
         {
             date = (Int32)DateTime.ParseExact(value, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
         }
         catch (Exception)
         {
             error.setError("RC004", "Incorrect date format. Expected yyyy/MM/dd HH:mm:ss");
             return(false);
         }
         return(setClaim(key, date.ToString(), error));
     }
     else
     {
         error.setError("RC001", "Wrong registered key value");
         return(false);
     }
 }
        public static bool validateClaim(string registeredClaimKey, string registeredClaimValue, long registeredClaimCustomTime, JwtSecurityToken token, Error error)
        {
            RegisteredClaim claim = RegisteredClaimUtils.getRegisteredClaim(registeredClaimKey, error);

            if (error.existsError())
            {
                return(false);
            }
            Int32 newTime = 0;

            switch (claim)
            {
            case RegisteredClaim.iss:
                return(SecurityUtils.compareStrings(token.Payload.Iss, registeredClaimValue));

            case RegisteredClaim.exp:
                int?exp = token.Payload.Exp;
                if (exp == null)
                {
                    return(false);
                }

                if (registeredClaimCustomTime != 0)
                {
                    newTime = (Int32)(DateTime.UtcNow.AddSeconds(-1 * registeredClaimCustomTime).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                }
                else
                {
                    newTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                }
                return((Int32)exp >= newTime);

            case RegisteredClaim.sub:
                return(SecurityUtils.compareStrings(token.Payload.Sub, registeredClaimValue));

            case RegisteredClaim.aud:
                IList <string> audience = token.Payload.Aud;
                return(SecurityUtils.compareStrings(audience[0], registeredClaimValue));

            case RegisteredClaim.nbf:
                int?nbf = token.Payload.Nbf;
                if (nbf == null)
                {
                    return(false);
                }

                if (registeredClaimCustomTime != 0)
                {
                    newTime = (Int32)(DateTime.UtcNow.AddSeconds(-(double)registeredClaimCustomTime).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                }
                else
                {
                    newTime = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                }
                return((Int32)nbf >= newTime);

            case RegisteredClaim.iat:
                int?iat = token.Payload.Iat;
                if (iat == null)
                {
                    return(false);
                }
                return(SecurityUtils.compareStrings(iat.ToString(), registeredClaimValue));

            case RegisteredClaim.jti:
                return(SecurityUtils.compareStrings(token.Payload.Jti, registeredClaimValue));

            default:
                error.setError("RC003", "Unknown registered Claim");
                return(false);
            }
        }