idp claim is missing on identityserver4 v2.1.1
Hi, I'm experimenting "idp claim is missing" in development environment (not tested in production, yet) with IdentityServer4 v2.1.1 and Asp.Net Core v2.0.5 for HybridAndClientCredentials flow. The starting point was your Quickstart6 with AsNetIdentity, with some personalized settings to AppDbContext. Anyway, the thrown exception is:
InvalidOperationException: idp claim is missing IdentityServer4.Extensions.PrincipalExtensions.GetIdentityProvider(IIdentity identity) in PrincipalExtensions.cs, line 203
the cookie ".AspNetCore.Identity.Application" at the moment of the exception was:
CfDJ8P8_6lWZfkhFrngXN9bMj7NCGXzHYrxket0Umm0fyQCr73STnkPvkxe090ZHyeklTl09cYTLxrojxnnqIoRaGYWvnIlYs-v9sKd7_Max8s5Sx9M3Q6DnxWRYAba3rqV_lfWJAVFDp0jOOW9FXwxGvPCPhkFH_hByhkRDbq27YSDDYZ8mIc6_bY-SO7JGFv37HCOa1ocnSd9pRqo_CjlxSr9xBAMibTqZQMZBzMf4EWk3TQ_2dnt88IvJ_xpDq2eZzAH1tjznov3_n2bqrkVEKx6oOERroVm8hvvDuV81zqYC0L3xaWyVHaNWqzkU48Z3KuLAryqEd3gWsK9QKRL_tNaIyKa7aNiuWpAykVpRkbfqgNHbyE68oernv1vmF7geLzhIcItKB2owLvTHNAQhMDs4MSdyeoyrZqkoW3jHnWqKuPPydJUhJupV9sf2RXZUsPxZfl_9Ea-ZtrllA77b_RIlaaCpFFqnXhK7iqLl-PNJVWEHMIfv7MwQ4RMiX8_tkgntGgAo9DI9WTPZo6ZxGqoT1w14sYu9Ot-T6s37kiWiIQiqGbOrZCt14-Vsemaa98MX5HN54-rbtTk44t4t2h7F6-Pchj6bmNleXDxG7DCm9ay5LAmu1vqGnG0l-K-m2qL9KgwIJZ5gRAFKc0cDAhBnh16edltK7nrIlSJWUP3TGPmAGka4rxLVTAD_yt-hS7pUUR_OZwE0dbX-Ob-ziWt4cYofT_c7F2JzI0ucf_dpQ8mV8hj3lPIte0WfAoIvU6eMNBwwa8xs5aysTdb1KMxPhJfOwbFDnSRMui5T7zqHh2V21a42f5cvZdJ6mDc-Go2PiFRvgVcK_OP4Bvk53YYJs5y2iKa1aSy6ja7H0gapnBQzfBFXDuDqHy3573CYiaZfOsQ_IwqXJTPMd6wuHu2iBD13SJk47BCBkTNhs3UMNFmvkKVrhpXzYC6DZO5tDGcaDhypj-oB0IzsiVq7TGgfIrs2NEuwIVBorAfHOr7FKnj0vH0sG5s-aOuXn-uGVtde0lGEbX3sJO1CogbjWwAWTvtv46PwFTv0N_YU0pIL3GQqWWpzCLhP0CalrRcf-C1-_yADmpaXEdDmHjF81ducUQRt1VizPo3BiC0TFbwE-sor9rzKESVyh5YjwcXNS2ugHhW5npgAMuinUJozYxN72FXHm7rZXO6apqh-XbmnfdPyycXUlQZ8LDYtM60Pi3tJrojCHEdJ2C0PFbOfuOY2RmGGL7YwTBTYpuT_5r4Vd4-7HOgVUBAlZjkZeWcMKogQRaDJq7FuMxhYKlNqaaaBDi0WSVz6gAwvIg4Xris03F19Jd--ul0GpyvrvbTgYH25AGSz2Qr7FCUJ-gBWnvmh3AgiplPhD5VULS0p3Wf3_vEnZjbfaEBEZ7s4NuUX6O2AAB4h-8Rj8NyCuavPAEkwMK-7mCFCgkIsrq57Wo1c9cmQJrD5SLBttabDY4536atgu_s4WN3oebt4TXdJqLWQzucm1DzUPaQKgqVeYUK_M8ioVaPikgKuU93QxI4LOpPpxqBo5x0Q4vSGER5UU-A
This exception is raised when I set the "remember me" flag and try to login again after some minutes (perahps with cookie expiration?). Startup.cs on identityserver side is:
` public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
services.AddIdentity<ApplicationUser, IdentityRole>(options=>
{
options.Lockout.MaxFailedAccessAttempts = 5;
options.Password.RequiredLength = 8;
options.Password.RequiredUniqueChars = 0;
options.Password.RequireDigit = true;
options.Password.RequireLowercase = true;
options.Password.RequireUppercase = true;
options.Password.RequireNonAlphanumeric = true;
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddTransient<IEmailSender, EmailSender>();
services.AddTransient<ISmsSender, SmsSender>();
services
.AddMvc()
.AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); })
;
services.AddKendo();
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.Configure<ClientsOptions>(Configuration.GetSection("Clients"));
services.AddIdentityServer()
.AddSigningCredential("CN=idsrv3test")
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 30;
})
;
services.AddAuthorization(options =>
{
options.AddPolicy(Costanti.PoliciesIdentityServer.AdminOnly, policy => policy.RequireRole(Costanti.Ruolo.Admin.ToString()));
options.AddPolicy(Costanti.PoliciesIdentityServer.ManagerAdmin, policy => policy.RequireRole(Costanti.Ruolo.Admin.ToString(), Costanti.Ruolo.Manager.ToString()));
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentityServer();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseKendo(env);
}
`
Startup.cs on client app side is:
` public Startup(IConfiguration configuration) { Configuration = configuration; //Clear all the default inbound claim types, By clearing inbound claims, we allow to use the new claims sent by token server. JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); }
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
string connectionString = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<DashboardDbContext>(options => options.UseSqlServer(connectionString));
services.AddMemoryCache(); //Permette l'utilizzo della Dependency Injection per sfruttare l'interfaccia IMemoryCache
services
.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
;
services.AddKendo();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddOptions();
services.Configure<SofiaOptions>(Configuration.GetSection("Sofia"));
services.Configure<ApiOptions>(Configuration.GetSection("Api"));
services.Configure<IdentityServerOptions>(Configuration.GetSection("IdentityServer"));
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.Cookie.Name = "FFDashCk";
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = Configuration.GetSection("IdentityServer").GetValue<string>("Url");
options.RequireHttpsMetadata = Configuration.GetSection("IdentityServer").GetValue<bool>("HttpsMetadata");
options.ClientId = Costanti.Clients.Dashboard;
options.ClientSecret = "xxxxxxxxxx";
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.UseTokenLifetime = false;
options.Scope.Clear();
options.Scope.Add("dashApi.dashboard");
options.Scope.Add("openid");
options.Scope.Add("offline_access");
});
services.AddAuthorization(options =>
{
options.AddPolicy(Costanti.PoliciesDashboard.Accesso, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[]{ Costanti.PermessiDashboard2.Accesso }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Anagrafica, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Anagrafica }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Obiettivi, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Obiettivi }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Pratiche, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Pratiche }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Produzione, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Produzione }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Analisi, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Analisi }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Estrazioni, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Estrazioni }))
);
options.AddPolicy(Costanti.PoliciesDashboard.Statistiche, policy => policy
.Requirements.Add(new PermessiDashboardRequirement(new Costanti.PermessiDashboard2[] { Costanti.PermessiDashboard2.Statistiche }))
);
});
services.AddTransient<IdentityServerServices>();
services.AddSingleton<IPermissionProvider, PermissionProvider>(); //Se non si fa ricorso alla Session, Singleton va benissimo
services.AddSingleton<IAuthorizationHandler, PermessiDashboardHandler>();
services.Configure<SecurityStampValidatorOptions>(opts =>
{
opts.OnRefreshingPrincipal = SecurityStampValidatorCallback.UpdatePrincipal;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, DashboardDbContext dashboardDbContext)
{
var cultureInfo = new CultureInfo("it-IT");
cultureInfo.NumberFormat.CurrencySymbol = "€";
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.UseKendo(env);
}
`
Any help would be appreciated. Thanks
Can you repro this in our samples and give us exect repo steps?
My starting point was your Quickstart - 6_AspNetIdentity but I'm unable to reproduce the issue on this example, so it's something I've personalized on my Application. Any idea to put me in the right direction to solve this issue?
There are several other issues in the archive which discuss this. Several have solutions that explain when this happens.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.