-
Notifications
You must be signed in to change notification settings - Fork 4k
Sometimes get a "idp claim is missing" with AspNetIdentity when authorizing #277
Comments
How do you sign in the user? |
Via a login endpoint. In this instance, the idp claim issue arose after automatically being accepted as being logged in (via cookies). |
Entirety of the login endpoint:
(which wasn't called in this instance, because already logged in) |
I see - so it maybe happens when the gets "slided" ? @brockallen ? |
I have made the same experiences. Usually this happens when (in dev) I restart the auth server (IdentityServer4) but not the MVC client and make a new request to an [Authorize]'d method within MVC app. The exact behavior I'll probably see today as I'll go further with implementing. |
Possibly. I did have a reminder for myself to look into this. |
I can confirm this behavior using ASP.NET Core Identity, too. SPA with Implicit using the popup mode. Code is the same as in your quickstarter examples. |
The cookie does not lose any claims when it slides, but it will lose claims if the security stamp is invalidated. Is this perhaps what you're running into? If any of you having this issue can confirm that it's not the cookie sliding, but instead the security stamp validation I'd appreciate it. Thanks! |
BTW, the properties are not lost so what we'll have to do is either 1) store these crucial claims in the properties, and then reload the claims from the properties, or, the less desirable option, 2) in our AddAspNetIdentity we replace the security stamp validator with all of the exact same logic as the built-in one, but instead we reload from the current claims rather than from the DB. |
How exactly is this validation performed? As in, is it ASP.Net identity related, and could it happen due to a server restart (I haven't explicitly set any secrets or anything about Identity) |
It's automatic within ASP.NET Identity. When anything related to the user's authentication changes (password, 2fa settings, email settings, etc). You can tell by the security stamp claim changing in the user's cookie. If you can't tell, then can you narrow down the exact repro steps so I can make sure what I'm seeing matches what you're seeing? Thanks. |
Unfortunately, I haven't found a consistent repro. Haven't made any changes to the user, though, at all. |
To test this I did these things:
|
I am getting the same exception idsvr aspnet core, client aspnet core. Also happens when auto authenticated through cookie.
|
I have this problem as well, OpenID Connect Implicit Flow. https://github.com/damienbod/AspNet5IdentityServerAngularImplicitFlow I can reproduce it by logging on directly to IdentityServer4, and then starting the SPA and the Implicit Flow login request causes this problem. Greetings Damien |
Ok, I now understand better what's happening. ASP.NET Identity always reloads the user's claims from the DB every 15m by default. This is done by the security stamp validator, but that behavior is odd given that it seems orthogonal the intended purpose of the security stamp validator. Anyway, I am now very confident that this is the reason behind this issue. I'll keep everyone posted on what we're going to do. |
Ok, I've added a custom security stamp validator to not reload claims from the DB. IdentityServer4.AspNetIdentity 1.0.0-rc1-update2 has been released to NuGet. Please test it and let us know how it's working. |
[remove] |
Ok, so there is what I experienced so far. Before Sign out in mvc:
When I then started an instance of idsvr and reloaded the mvc page or tried to get to an secured page ([Authorized]) it would throw the Doing these steps is probably not the use case and I haven't digged into the whole problem so I don't know if this is by design or just me being inconsistent in (re-)starting servers... Anyway, with |
I have updated and done some initial tests. I cannot reproduce this problem anymore. Greetings Damien |
Ok, good to hear. Thanks. |
@brockallen I'm experiencing this issue as well.
I don't understand this. Why would periodically reloading the user's claims cause this problem? |
Because idp is a claim captured at login time, and is not something stored in the DB. |
Ok, I follow that. This issue appears for me right off the bat though, and it's 100% of the time - it smells like a misconfiguration on my part, but I am having a hard time figuring out what it would be. |
For anyone else who might have landed here: It's important to call |
@brockallen @aggieben Moving on to app.UseIdentity();
app.Map("/auth", authApp =>
{
authApp.UseIdentityServer();
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
}); This causes the aforementioned Is there a better way to do this, or does this mean this issue is still active? |
@artiomchi the map method doesn't fall through, as such, to the middleware underneath - therefore, MVC is not configured for the |
Nope, seems to be running into the same issue. I've tried app.Map("/auth", authApp =>
{
authApp.UseIdentityServer();
authApp.UseMvcWithDefaultRoute();
}); Actually, doing some more testing and I uncovered some interesting things..
So my guess is that within IdentityServer, the base url gets set, which affects all requests and URL builds to the site, including redirects to the login pages. I did a quick glance at the code, and something like that is being set here, but without a deeper code analysis, I might just be looking at a red herring :) |
P.S. Just tried restricting the child route to only catch the Connect controller, and it behaves the same as points 2/3 above app.Map("/auth", authApp =>
{
authApp.UseIdentityServer();
authApp.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "Connect/{action=Index}/{id?}",
defaults: new { Controller = "Connect" });
});
}); |
You can override the login/etc urls when you add identity server in the
configure services section. Maybe combining your first attempt with that to
ensure it goes to the right page for JS etc would be a temporary
workaround?
…On Thu, Jun 8, 2017, 21:33 Artiom Chilaru ***@***.***> wrote:
P.S. Just tried restricting the child route to only catch the Connect
controller, and it behaves the same as points 2/3 above
app.Map("/auth", authApp =>
{
authApp.UseIdentityServer();
authApp.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "Connect/{action=Index}/{id?}",
defaults: new { Controller = "Connect" });
});
});
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#277 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAuZT2nV3t6m-wb8eQ2grAXk_SoFJd74ks5sB9wbgaJpZM4J4uYT>
.
|
So... You mean something like this? services.AddIdentityServer(x =>
{
x.UserInteraction.LoginUrl = "/account/login";
}) Nope.. It builds the login url based on the relative path. Just to be sure, I changed it to Could this issue be re-opened or a new issue created for this, as this means I can't use the IS4 at all in my current environment, and that prevents me from upgrading to ASP.NET Core MVC :( |
open a new issue |
I'm experiencing the same issue, I'm using IdentityServer4 and from time to time I found in logs 'Unhandled exception: System.InvalidOperationException: idp claim is missing' or 'IdentityServer4 message: idp claim is missing stack: at IdentityServer4.Extensions.PrincipalExtensions.GetIdentityProvider(IIdentity identity)'. |
The issue is back with version |
Same as @YZahringer after upgrading to 2.0.0-rc1 |
Same issue here: |
Any updates on this? |
Since this issue has been closed I opened a new one here: #1573 |
Just as a follow on note here about this issue. This error happens when you don't have the main authentication cookie scheme set as the default sign-in scheme in ASP.NET Core. This is usually the case when you use ASP.NET Identity, because it internally set the sign in scheme to be the external authentication cookie scheme. |
If it helps, I have just got this problem when using Postman, and Requesting an 'Authorization Code' token. Nuget packages:
Stacktrace:
To clarify, changing: services.AddAuthentication()
.AddCookie("Cookies") to services.AddAuthentication("Cookies")
.AddCookie("Cookies") Makes the
|
Solved In order to get the following working again: services.AddAuthentication()
.AddCookie("Cookies") I had to delete the users from the database, then re-add them. And magically To replicate the error use: services.AddAuthentication()
.AddCookie("Cookies") Add a user and check you can login ok. services.AddAuthentication("Cookies")
.AddCookie("Cookies") Go to view grants, and you should now be stuck in a login loop. services.AddAuthentication()
.AddCookie("Cookies") You now get the `idp claim is missing' To solve, delete the user, and re-add user again. So something in the AspNetUsers table changed. |
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. |
IS4 entries in project.json:
I'm using ASP.Net Core Identity, and I've included the IdentityServer4 token validation library (I want to secure an api for user creation etc as part of the same service).
Here are the claims that are set on the current identity:
Is this just a "we should allow returning null for the provider"? Or is there a further underlying issue/misconfiguration? In this instance, I'm only supporting one IDP, so I don't personally mind a bandaid fix.
The text was updated successfully, but these errors were encountered: