public static JwtSecurityToken CreateToken(this ClaimsIdentity Identity) { if (Identity != null && Identity.Claims.Count() > 0) { var _token = new JwtSecurityToken( issuer: JwtOptions().Value.Issuer, audience: JwtOptions().Value.Audience, claims: Identity.Claims, notBefore: DateTime.UtcNow, expires: DateTime.UtcNow.Add(JwtOptions().Value.Expiration), signingCredentials: JwtOptions().Value.SigningCredentials); if (DictionaryToken.Any(n => n.Key.Equals(_token.Subject, StringComparison.OrdinalIgnoreCase))) { DictionaryToken[_token.Subject] = new JwtSecurityTokenHandler().WriteToken(_token); } else { DictionaryToken.Add(_token.Subject, new JwtSecurityTokenHandler().WriteToken(_token)); } return(_token); } return(null); }