我正在尝试将JWT发送到我的依赖方策略中并通过<InputTokenFormat>JWT</InputTokenFormat>
进行引用,但是很难让B2C来验证令牌。我想知道是否有人可以发现问题。
错误
这是在调用授权端点并在查询字符串中传递client_assertion之后从B2C返回的:
AADB2C90017:请求中提供的客户端断言无效:“ client_secret”用作验证密钥
client_secret是一个签名机密,是在IEF策略区域中手动生成的,用于与应用程序共享。但老实说,我无法确定此错误是否只是一个有用的事实:“ client_secret”是策略尝试验证的关键,或者,它告诉我为什么请求无效:“ client_secret”被错误地用作验证密钥。
来自App Insights
{
"Key": "Exception",
"Value": {
"Kind": "Handled",
"HResult": "80131500",
"Message": "The client assertion provided in the request is invalid: 'client_secret' was used as the verification key",
"Data": {
"IsPolicySpecificError": false
},
"Exception": {
"Kind": "Handled",
"HResult": "80131500",
"Message": "The validation of the JWT failed. Reason: jwt format",
"Data": {}
}
}
已解码的JWT :
(请注意,aud
Guid是我的应用的客户端ID)
{
"alg": "HS256",
"typ": "JWT"
}
.{
"verified_email": "markarnolditpro@gmail.com",
"nbf": 1554098875,
"exp": 1554530875,
"iat": 1554098875,
"iss": "https=mytenant.b2clogin.com/34d8169d-0e97-4cc7-a8d0-57c29404f1b1/v2.0/",
"aud": "7c93185b-05c7-4d72-b8c9-bd62e7bfefc5"
}
.[Signature]
策略的URL:
https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1A_Invitation
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&client_assertion=<JWT base64 header.body.signature>
&client_id=7c93185b-05c7-4d72-b8c9-bd62e7bfefc5
&response_mode=form_post
&response_type=id_token
&redirect_uri=http://localhost:34647/
&scope=openid
&nonce=123123123sdfsdfsdf
签名
我创建了一个IEF密钥,手动生成了该密钥,并对其进行了签名,并与该应用共享了该值。我引用依赖部分策略中的密钥,如下所示:
<Key Id="client_secret" StorageReferenceId="B2C_1A_ADB2CMgtAPISecret" />
生成令牌
此代码大部分来自WingTipGames应用
private static string CreateSelfIssuedToken(
string issuer,
string audience,
TimeSpan expiration,
string signingSecret,
ICollection<Claim> claims)
{
var tokenHandler = new JwtSecurityTokenHandler();
var nowUtc = DateTime.UtcNow;
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(signingSecret));
var signingCredentials = new SigningCredentials(key, "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256");
var tokenDescriptor = new SecurityTokenDescriptor
{
Audience = audience,
Expires = nowUtc.Add(expiration),
IssuedAt = nowUtc,
Issuer = issuer,
NotBefore = nowUtc,
SigningCredentials = signingCredentials,
Subject = new ClaimsIdentity(claims)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
return tokenHandler.WriteToken(token);
}
我相信,将使用相同的签名秘密来对JWT进行签名和验证。但是我真的是盲目的需要的特定jwt格式。有什么想法吗?到目前为止,我在想:
谢谢 标记