Example #1
0
        public static string RefeshToken(this JwtSecurityToken jwt)
        {
            if (DictionaryToken.Any(n => n.Key.Equals(jwt.Subject, StringComparison.OrdinalIgnoreCase)) && jwt.ValidTo > DateTime.UtcNow)
            {
                jwt = new JwtSecurityToken(
                    issuer: JwtOptions().Value.Issuer,
                    audience: JwtOptions().Value.Audience,
                    claims: jwt.Claims,
                    notBefore: DateTime.UtcNow,
                    expires: DateTime.UtcNow.Add(JwtOptions().Value.Expiration),
                    signingCredentials: JwtOptions().Value.SigningCredentials);
                return(DictionaryToken[jwt.Subject] = new JwtSecurityTokenHandler().WriteToken(jwt));
            }

            //Token Expirated
            if (DictionaryToken.Any(n => n.Key.Equals(jwt.Subject, StringComparison.OrdinalIgnoreCase)))
            {
                DictionaryToken.Remove(DictionaryToken.FirstOrDefault(n => n.Key.Equals(jwt.Subject, StringComparison.OrdinalIgnoreCase)).Key);
            }
            return(null);
        }