使用 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
// ...
}
}
}
然后就可以在异常信息中看到更加完整的信息了, 方便开发调试...