我正在尝试使用 JWT 令牌验证用户。我下面使用的代码在控制台应用程序中运行得非常好。但是当我想将它应用到我的 Azure 函数中时,它给出了错误:
Could not load file or assembly Microsoft.IdentityModel.Tokens
我的解决方案中确实有另一个 Azure 函数,但它不使用此 NuGet 包。我已经看过这个链接:
无法加载文件或程序集“Microsoft.IdentityModel.Tokens,版本=5.2.0.0” https://stackoverflow.com/questions/53341678/could-not-load-file-or-assembly-microsoft-identitymodel-tokens-version-5-2-0-0
我无法从中得到任何东西。那么我做错了什么?提前致谢
string key = "";
var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
var header = new JwtHeader(credentials);
var payload = new JwtPayload
{
{ "some ", "hello "},
{ "scope", "http://dummy.com/"},
};
var secToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(secToken);
var token = handler.ReadJwtToken(tokenString);
log.LogInformation(token.ToString());
通过在 .csproj 文件中添加一行代码解决了这个问题
<PropertyGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)