我试图弄清楚如何使用 IdentityModole framwork 为 JWT 场景的代码流定义我的 AuthorizationCodeTokenRequest
假设我的 OP 服务器上有一个已定义的客户端
new Client
{
ClientId = "myClientId"
ClientSecrets = {
new Secret("MyVerySpecialSecret".Sha256())
}
在客户端,我想使用JWT获取 AuthorizationCode
var securityToken = tokenHandler.CreateJwtSecurityToken(
issuer: clientID,
audience: opEndPoint.TokenEndpoint,
subject: new ClaimsIdentity(new List<Claim>()
{
new Claim(JwtClaimTypes.JwtId, Guid.NewGuid().ToString()),
new Claim(JwtClaimTypes.Subject, clientID),
new Claim(JwtClaimTypes.IssuedAt, new DateTimeOffset(now).ToEpochTime().ToString(),
ClaimValueTypes.Integer64)
}),
expires:now.AddMinutes(5),
signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MyVerySpecialSecret")), SecurityAlgorithms.HmacSha256Signature)
);
var clientAuthJwt = tokenHandler.WriteToken(securityToken);
var request = new AuthorizationCodeTokenRequest()
{
Address = opEndPoint.TokenEndpoint,
ClientId = clientID,
Code = code,
ClientAssertion = new ClientAssertion()
{
Type = OidcConstants.ClientAssertionTypes.JwtBearer,
Value = clientAuthJwt
},
RedirectUri = opEndPoint.RedirectUri,
GrantType = OidcConstants.GrantTypes.AuthorizationCode
};
var response = client.RequestAuthorizationCodeTokenAsync(request).Result;
我得到“invalid_client”,所以很明显我使用的 SigningCredentials 不正确,无法在任何地方找到工作代码示例。