Exemple #1
0
        public void CreateBlacklistToken(string token)
        {
            BlacklistToken blToken = new BlacklistToken
            {
                Token = token
            };

            _db.BlacklistTokens.Add(blToken);
            _db.SaveChangesAsync();
        }
Exemple #2
0
        public static IDictionary <string, object> DecodeToken(string token)
        {
            var secret = ConfigurationManager.AppSettings["jwt.secret"];

            try
            {
                // first check if it is blacklisted
                BlacklistToken blt = (new DataHelper()).FindBlacklistToken(token);
                if (blt != null)
                {
                    throw new TokenExpiredException("Blacklisted");
                }

                IJsonSerializer   serializer = new JsonNetSerializer();
                IDateTimeProvider provider   = new UtcDateTimeProvider();
                IJwtValidator     validator  = new JwtValidator(serializer, provider);
                IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
                IJwtDecoder       decoder    = new JwtDecoder(serializer, validator, urlEncoder);

                IDictionary <string, object> payload = decoder.DecodeToObject(token, secret, true);
                return(payload);
            }
            catch (TokenExpiredException e)
            {
                // log expired token
                return(new Dictionary <string, object>()
                {
                    { "error", e.Message }
                });
            }
            catch (SignatureVerificationException e)
            {
                // log invalid signature
                return(new Dictionary <string, object>()
                {
                    { "error", e.Message }
                });
            }
        }
 public BlacklistToken Update(BlacklistToken param)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
        public BlacklistToken FindBlacklistToken(string token)
        {
            BlacklistToken blt = _db.BlacklistTokens.Where(t => t.Token == token).FirstOrDefault();

            return(blt);
        }