我为visual studio 2012安装了“用于Microsoft .Net Framework 4.5的JSON Web令牌处理程序”的Nuget包(链接: - http://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/)。但它不包含“X509SecurityToken”的定义。导致以下方法显示错误的原因......
private static void ValidateToken(string Token)
{
var tokenHandler = new JwtSecurityTokenHandler();
var validationParameters = new TokenValidationParameters()
{
ValidAudience = "<some url>",
IssuerSigningTokens = new List<X509SecurityToken>() { new X509SecurityToken(
X509
.LocalMachine
.My
.Thumbprint
.Find("112233445566xxyy", false)
.First()) },
ValidIssuer = "https://my-issuer.com/trust/issuer",
CertificateValidator = X509CertificateValidator.None,
RequireExpirationTime = true
};
try
{
SecurityToken validatedToken;
var principal = tokenHandler.ValidateToken(Token, validationParameters, out validatedToken);
}
catch (Exception e)
{
Console.WriteLine("{0}\n {1}", e.Message, e.StackTrace);
}
Console.WriteLine();
}
如果有人能提供任何帮助甚至提示,我将不胜感激,
感谢您的帮助, Kushan Randima。
答案 0 :(得分:1)
尝试添加对System.IdentityModel的引用。