Identity Server Login - A task was canceled #481
-
|
We are experiencing an inconsistent authentication state when a login flow is interrupted/cancelled (tab closed, navigation interrupted, refresh at the wrong time). What happens (step by step) SignInManager<AspNetUser> _signInManager;
await _signInManager.CheckPasswordSignInAsync(user, hashedPassword, false);After business logic (partner resolution, additional checks, etc.), we sign in the user manually:
During or immediately after this step, the login flow is interrupted (tab closed, navigation cancelled, etc.). We have logic similar to: if (User?.Identity?.IsAuthenticated == true)
{
// redirect back (already logged in)
}Since IdentityServer still has the auth cookie from the interrupted attempt, IdentityServer immediately redirects the user back to the SPA without establishing a valid BFF session. This creates a loop: Key problem: Question Specifically, is there any supported way to use a CancellationToken (or HttpContext.RequestAborted) to interrupt the login flow so that the user is not signed in on the IdentityServer side when the request is cancelled? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
Is your BFF part of your Duende IdentityServer solution by any chance? Or are these two sharing the same cookie? When your BFF needs to authenticate the current user, it should start an OAuth + OpenID Connect flow to IdentityServer:
The way you're describing the situation, leads me to believe that the OIDC flow isn't happening as its supposed to. Either because of custom code on the IdentityServer side of things, or because you're sharing cookies between the BFF and IdentityServer, which you shouldn't be doing. |
Beta Was this translation helpful? Give feedback.
I'm inclined to answer "yes", but it could still depend on where this short-circuit is happening. It's definitely a good approach to first verify whether there is a valid authorization context before using the return URL value, but I'm still confused why you had to add this short-circuit logic.
When the authorize endpoint redirects the user back to the login UI, it most likely had a good reason to do so.