根据我在网上找到的一些示例,我为我的 Asp.net Core REST 服务构建了一些 JWT 中间件。我知道响应看起来像:
{
"access_token":"...",
"expires_in":3600,
"refresh_token":"???",
"token_type": "Bearer",
}
我了解如何创建 access_token:
Claim[] claims = new Claim[]
{
new Claim(JwtRegisteredClaimNames.Sub, strUsername),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Iat, dtNow.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64)
};
JwtSecurityToken jwtAccess = new JwtSecurityToken(_options.Issuer, _options.Audience, claims, dtNow.DateTime,
dtNow.DateTime.Add(_options.AccessTokenExpiration), _options.SigningCredentials);
问题是如何创建 refresh_token?我搜索了高低,找不到太多关于它的文档。基本上每个参考资料都说“它是存储在数据库中的令牌,具有更长的 TTL,您可以从中创建新的 access_token ”。
那么 refresh_token 是否与 access_token 完全相同,只是 TTL 更长,并且它针对数据库验证了额外的步骤?
我见过的一些示例 JWT 响应似乎 refresh_token 要短得多。我的 access_token 使用 RSA515 使用证书签名,所以字符串有点长......