无法加载文件或程序集 Microsoft.IdentityModel.Tokens 问题

Dan*_*del 9 c# jwt

我正在尝试使用 JWT 令牌验证用户。我下面使用的代码在控制台应用程序中运行得非常好。但是当我想将它应用到我的 Azure 函数中时,它给出了错误:

Could not load file or assembly Microsoft.IdentityModel.Tokens

我的解决方案中确实有另一个 Azure 函数,但它不使用此 NuGet 包。我已经看过这个链接:

无法加载文件或程序集“Microsoft.IdentityModel.Tokens,版本=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());
Run Code Online (Sandbox Code Playgroud)

Dan*_*del 17

通过在 .csproj 文件中添加一行代码解决了这个问题

<PropertyGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)