在学习IdentityServer4时,使用client访问Api时报错System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden. For more details, see https://aka.ms/IdentityModel/PII.]'.
经过仔细排查,发现是API访问的地址有误:
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = "http://localhost:5001";//这个是错误地址
options.RequireHttpsMetadata = false;//如果不使用Https,则需要配置这个
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
};
IdentityModelEventSource.ShowPII = true;
});
如上options.Authority的地址写成了Api的地址,这里实际应该是IdentityServer的地址,我的是http://localhost:5000,改了之后,重新运行,即可正常访问。
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = "http://localhost:5000";//此处应该是IdentityServer的地址
options.RequireHttpsMetadata = false;//如果不使用Https,则需要配置这个
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
};
IdentityModelEventSource.ShowPII = true;
});