Allow an identity to be received multiple times
If I successfully authenticate as a specific identity and I attempt another log in through the same provider again, I end up getting redirected to the access denied route. This prevents me from creating an idempotent single signin flow.
- Because the handler remains in control for the entirety of the flow, I'm unable to preempt it in any way.
- Even if I could preempt, I then run into this issue: https://github.com/aspnet/Security/issues/1066
- Configuring a different access denied path seems disingenuous as there could still be legitimate reasons for denying access outside of this scenario.
Related to this, but a slightly different problem, is https://github.com/aspnet/Security/issues/1056. Maybe addressing this ticket can be rolled in with the design work to be done there?
This check was added to prevent infinite loops that people often found themselves in due to authorization issues. Why are you issuing a challenge for an already authenticated user? This seems like an issue in your authorization policy.
The initial user action comes in from an external system, although I do initiate a challenge, that's more or less secondary to my issue: It's plausible that they could authenticate from the external system as different external identities, so even though I may already have my own identity established for their cookie, the scheme could be used multiple times.
For example you want them to be able to authenticate with multiple AAD accounts at the same time?
Really it could be any account multiple times. So imagine:
[email protected] and [email protected]
If he signs in with [email protected], he'll at some point establish an identity belonging to my site as I'll have maintained associations of @gmail.com users to my internal domain users.
If he signs out of [email protected] google-side and then signs into [email protected], he'll still be authenticated as the first domain user in my application.
Authenticating as [email protected] will go through a clever flow to determine whether a user already exists (in which case that 2nd internal domain user would be authenticated), or Bob would be prompted if he wishes to associate [email protected] to the first domain user.
This is just good UX, but I'm finding it difficult to implement in situations where I receive an identity from a scheme that has already provided one.
Any news on this? Just came across the same issue.
Yeah, the middleware is making an assumption that really should be up to me. The assumption being one identity per scheme. Which isn't correct or helpful.
Our template (e.g. Identity framework) uses two cookies to manage scenarios like this. The first is a temporary cookie that stores the external login data during the signin flow. Once you've completed the external login then you cross reference the external id with a local id and issue an 'application' cookie for the local id. At this point the temporary cookie can/should be deleted. Then you can start another external login flow with any provider and associate it with the local id when it's done.
I'm not sure what you described speaks to the issue here.
The problem isn't about not being able to use two separate authentication schemes. The problem is about not being able to use the same one twice. I'm not even sure cookies has anything to do with it actually.
A redirect is incorrectly being generated when a successful authentication comes in for a scheme that has already provided an identity. That redirect really shouldn't be happening because it's entirely legitimate to expect:
- The same login multiple times from a scheme, regardless of whether that scheme has provided an identity or not
- A different identity from the same scheme, whether that scheme has already provided an identity or not
The multiple cookies approach allowes you to hold onto one identity while processing a second one, from the same or different provider.
@haok, this ask is similar to the discussion we had about moving the challenge vs forbid logic to the authorization layer so it could be a policy decision.
Challenge vs Forbid is not an authorization concern, the authorization service is given the claims principal and requirements to authorize against, it doesn't know how to get a principal at all (that's authentication). Today its the MVC authorization filter that has the logic to build the principal to pass into the actual authorization service, certainly we can make adjustments in the filter's logic, but the core Authorization package doesn't depend on authentication today.
@HaoK in our meeting you thought there might be a way to do this with a custom auth filter - can you share some pointers?
You can try replacing the default authorize filter with one where: instead of returning the build in challenge result, you return a result that explicitly passes in the challenge behavior:
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs#L160
Use the overload of context.Authentication.Challenge that specifies the ChallengeBehavior.Unauthorized explicitly instead https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs#L111