Closed thomaslevesque closed 6 years ago
Apparently this is a known issue:
Current workaround:
public class SignInManagerWithCorrectProviderDisplayName<TUser> : SignInManager<TUser>
where TUser : class
{
public SignInManagerWithCorrectProviderDisplayName(UserManager<TUser> userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory<TUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor, ILogger<SignInManager<TUser>> logger, IAuthenticationSchemeProvider schemes)
: base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
{
}
public override async Task<ExternalLoginInfo> GetExternalLoginInfoAsync(string expectedXsrf = null)
{
var info = await base.GetExternalLoginInfoAsync(expectedXsrf);
if (info != null)
{
var schemes = await GetExternalAuthenticationSchemesAsync();
var scheme = schemes.FirstOrDefault(s => s.Name == info.LoginProvider);
if (!string.IsNullOrEmpty(scheme?.DisplayName))
info.ProviderDisplayName = scheme.DisplayName;
}
return info;
}
}
You are, as you've discovered, conflating the display name with the scheme. So your workaround isn't a work around, it's the right way to do it, it's what it done in templates. There's no bug here, it's by design.
@blowdart I'm confused... Are you saying that ExternalLoginInfo.ProviderDisplayName
is supposed to return the same thing as ExternalLoginInfo.LoginProvider
and isn't supposed to actually return a display name? In this case the property is useless...
it's what it done in templates
Which templates are you referring to? I don't think the Identity template does this; I wouldn't have needed the workaround if it did.
If you're talking about this, it doesn't even attempt to use a display name, it just uses LoginProvider
, which is a "technical" name not intended to be seen by users.
Ah I misread the issue, yep its a bug, we can fix this in 2.2
The default UI does use the DisplayName here https://github.com/aspnet/Identity/blob/master/src/UI/Areas/Identity/Pages/Account/Login.cshtml#L69 so the templates should be affected by this bug too
The default UI does use the DisplayName here https://github.com/aspnet/Identity/blob/master/src/UI/Areas/Identity/Pages/Account/Login.cshtml#L69 so the templates should be affected by this bug too
Some places use the display name, others use the provider name, e.g.:
@hoak We should fix them all to be consistent.
Would you be willing to accept a PR for this?
Sure that would be great
Thanks @thomaslevesque !
I use ASP.NET Identity with Azure AD as an external identity provider. I configured Azure AD with a display name:
When I call
SignInManager.GetExternalAuthenticationSchemesAsync()
, I would expectProviderDisplayName
in the result to be "Azure Active Directory", but it's "AzureAD" instead.