關閉。這個問題需要除錯細節。它目前不接受答案。
想改進這個問題?更新問題,使其成為 Stack Overflow的主題。
3天前關閉。
改進這個問題我已經為此苦苦掙扎了幾天......這里似乎有許多類似的問題,但我找不到涵蓋這種確切情況的問題。
我有一個節點服務,它正在創建一個 jsonwebtoken NPM 包(RS256)。任何其他節點服務都能夠驗證 UI 提供的令牌并讀取宣告 _ 也可以在 jwt.io 上進行驗證。
但是我需要在解決方案中添加一個 .net 核心 api,我不能簡單地無法讓它作業 - 我覺得我已經嘗試了一百萬種不同的設定 api 中間件的組合,但顯然我有一些東西丟失了,我找不到任何正確方法的檔案 - 顯然我也想閱讀宣告,但現在,在我拔掉頭發之前,我只想驗證令牌并點擊控制器。
uj5u.com熱心網友回復:
在使用包中的AddJwtBearer擴展方法時配置JWT不記名身份驗證(以及令牌驗證選項):DIMicrosoft.AspNetCore.Authentication.JwtBearer NuGet
// The below code used to be in Startup.ConfigureServices method
// before the minimal API with all stuff in Program.cs file has been introduced
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ValidateIssuer = true,
... = ,
};
options.Authority = <settings-your-authority>;
options. ect..
});
...
// Use configured JWT auth (used to be in Startup.Configure method)
var app = builder.Build();
...
app.UseAuthentication();
...
app.Run();
并在此處查看如何在 C# 中使用 RS256(非對稱)驗證 JWT
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/473345.html
