我正在尝试将GIT集成到我的网站中。我已成功实施该工具包,并希望使用安装期间提供的* .p12证书验证从Google API发送的JWT。
异常详细信息:System.IdentityModel.SignatureVerificationFailedException:IDX10501:签名验证失败。密钥尝试:'System.IdentityModel.Tokens.X509SecurityKey'。
收到的JSON Web令牌: token:'{“alg”:“RS256”,“kid”:“qwYevA”}。{“iss”:“https://identitytoolkit.google.com/”,“aud”:“238895676270-i8o5fe2poogs83nki8jl5tgtfm7h9n5l.apps.googleusercontent.com”, “IAT”:1445739256, “EXP”:1446948856, “USER_ID”: “”, “电子邮件”: “”, “PROVIDER_ID”: “google.com”, “验证”:真实的, “DISPLAY_NAME”: “”}”
var signingToken = new X509SecurityToken(new X509Certificate2(fileName, "notasecret"));
TokenValidationParameters validationParameters =
new TokenValidationParameters()
{
IssuerSigningKey = new X509SecurityKey(new X509Certificate2(fileName, "notasecret")),
ValidAudience = "238895676270-i8o5fe2poogs83nki8jl5tgtfm7h9n5l.apps.googleusercontent.com",
ValidIssuer = "https://identitytoolkit.google.com/",
IssuerSigningKeyResolver = (token, a, ski, tvp) => { return new X509SecurityKey(new X509Certificate2(fileName, "notasecret")); },
IssuerSigningToken = signingToken,
};
SecurityToken st;
var result = tokenHandler.ValidateToken((Request.Cookies["gtoken"]).Value, validationParameters, out st);
答案 0 :(得分:1)
Identity Toolkit生成的JWT由Identity Toolkit自己的RSA私钥签名,而不是您在安装过程中下载的.p12。
您需要从https://www.googleapis.com/identitytoolkit/v3/relyingparty/publicKeys?key={YOUR_SERVER_API_KEY}
下载当前有效的Identity Toolkit X509公共证书,然后选择孩子的证书'在您收到的JWT中,使用该证书构建X509Certificate2。
可以在已创建OAuth2客户端的Google Developers Console中生成SERVER_API_KEY。