问题描述
我们已经使用IdentityServer4实现了Identity-Provider。最近,我们将应用程序升级到.net core 3.1(从2.1),并通过它将IdentityServer4-Nuget-Packages从版本2.2.0升级到了3.1.3。
这些是旧状态(使用.net 2.1和IdentityServer4 2.2.0提供)的访问令牌的实际内容
{
"nbf": 1597236398,"exp": 1597239998,"iss": "https://lab10vm-tri-2:8777/usermgmt/identityprovider","aud": [
"https://lab10vm-tri-2:8777/usermgmt/identityprovider/resources","basecommon"
],"client_id": "Webportal","sub": "d860efca-22d9-47fd-8249-791ba61b07c7","auth_time": 1597236392,"idp": "local","upn": "Administrator","scope": [
"openid","profile","amr": [
"pwd"
]
}
以下是新状态(.net 3.1和IdentityServer4 3.1.3)提供的访问令牌的内容:
{
"nbf": 1597236389,"exp": 1597239989,"iss": "https://lab10vm-tri-3:8777/usermgmt/identityprovider","aud": "basecommon","auth_time": 1597236383,"amr": [
"pwd"
]
}
如您所见,旧版本包含一个称为“ https:// lab10vm-tri-2:8777 / usermgmt / identityprovider / resources”的受众,而新版本则没有。
请告诉我:如何恢复以前的行为,以便吸引观众?
我尝试过的方法:Google非常非常喜欢诸如“ IdentityServer 3.1听众丢失”之类的话题。 我以这种方式发现的所有结果都与我的情况不符,而且我也不知道要看哪里了。
解决方法
尝试升级到IdentityServer 4的4.0x版本,请在最新版本中重新考虑。因为我在3.13版本中没有看到它,但是我看到它出现在v4.0.0中
,设置IdentityServer4时需要设置options.EmitLegacyResourceAudienceClaim = true;
,默认值为false。
它发出aud
格式的issuer/resources
声明
这是您的代码的外观:
namespace IdentityServer
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServer(
options =>
{
options.EmitLegacyResourceAudienceClaim = true; //Default value is false
})
.AddInMemoryIdentityResources(Config.Ids)
.AddInMemoryApiResources(Config.Apis)
.AddInMemoryClients(Config.Clients)
.AddTestUsers(TestUsers.Users);
}
}
}
详细了解EmitLegacyResourceAudienceClaim
here