使用 Microsoft.AspNetCore.Authentication.JwtBearer
做驗證的時候報錯如下:
IDX10503: Signature validation failed. Keys tried: '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
Exceptions caught:
'[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
token: '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
訪問鏈接后, 只看到下面這段話:
By default, we do not include any potential PII (personally identifiable information) in our >exceptions in order to be in compliance with GDPR.
If you need to see the full information present in exceptions, please set >IdentityModelEventSource.ShowPII to true.
IdentityModelEventSource.ShowPII = true;
意思是出於安全的原因, 不會直接顯示用戶個人信息, 也就是 PII, 但是可以通過啟用 IdentityModelEventSource.ShowPII = true
來查看完整的異常信息.
這里有個官網的屬性說明 IdentityModelEventSource.ShowPII Property
完了之后, 又是一個懵逼點, 這貨在哪里設置? 代碼應該寫在哪里?
在 ASP.NET Core 項目中, 我們可以在 Startup.cs
的 Configure()
中來直接配置該屬性.
// ...
using Microsoft.IdentityModel.Logging
namespace AspNetCoreShowPII
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// ...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
IdentityModelEventSource.ShowPII = true; // here
// ...
}
}
}
然后就可以在異常信息中看到更加完整的信息了, 方便開發調試...