Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwoFactorSignIn overwriting IdP for ExternalProviders #17

Open
zyofeng opened this issue Aug 28, 2021 · 1 comment
Open

TwoFactorSignIn overwriting IdP for ExternalProviders #17

zyofeng opened this issue Aug 28, 2021 · 1 comment

Comments

@zyofeng
Copy link

zyofeng commented Aug 28, 2021

At the moment, if an external user is flagged as requiring 2FA, the controller redirects the user to SendCode/VerifyCode flow, which ends with the following line of code

var result = await _signInManager.TwoFactorSignInAsync(model.Provider, model.Code, model.RememberMe, model.RememberBrowser);

This overwrites the IdP claim against the ClaimsPrincipal with "Local", which prevents upstream logout here

if (idp != null && idp != IdentityServerConstants.LocalIdentityProvider)

The workaround I have without having to rewrite TwoFactorSignInAsync is this, I am wondering if there is a more elegant solution?

var result = await _signInManager.TwoFactorSignInAsync(model.Provider, model.Code, model.RememberMe, model.RememberBrowser).ConfigureAwait(false);

//This is a workaround to override the Idp if it's an external provider
if (result.Succeeded)
{
var info = await _signInManager.GetExternalLoginInfoAsync().ConfigureAwait(false);
if (info != null)
return await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, model.RememberMe, true).ConfigureAwait(false);
return result;
}

@damienbod
Copy link
Owner

@zyofeng I think this could be improved by using different schemes. I would need to look more into detail to understand this better.

Greetings Damien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants