【发布时间】:2020-01-10 01:43:12
【问题描述】:
如何在生成访问令牌时将userId 参数添加到jwt 的负载中?
我在asp.net core 2.2 上工作,我需要将userId 参数添加到生成访问令牌 的负载中,然后生成JSON 格式的结果。
public string GenerateTokens(string userId)
{
var Claims = new Claim[]
{
new Claim(JwtRegisteredClaimNames.Sub,userId)
};
var signingkey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is secret phrase"));
var SigningCredntials = new SigningCredentials(signingkey, SecurityAlgorithms.HmacSha256);
var Jwt = new JwtSecurityToken();
return new JwtSecurityTokenHandler().WriteToken(Jwt);
}
【问题讨论】:
-
有什么不清楚的地方
标签: c# asp.net-mvc asp.net-core jwt