Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

DisplayName in new AuthN Plumbing? #1319

Closed
leastprivilege opened this issue Jul 13, 2017 · 27 comments
Closed

DisplayName in new AuthN Plumbing? #1319

leastprivilege opened this issue Jul 13, 2017 · 27 comments
Assignees
Milestone

Comments

@leastprivilege
Copy link
Contributor

How do I set it? It's gone from the options class.

@Tratcher
Copy link
Member

public virtual AuthenticationBuilder AddScheme<TOptions, THandler>(string authenticationScheme, string displayName, Action<TOptions> configureOptions)

public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, string displayName, Action<AuthenticationSchemeBuilder> configureScheme, Action<TOptions> configureOptions)

@HaoK is this exposed anywhere else? E.g. I don't see a way to change it for Google, OIDC, etc..

@Tratcher
Copy link
Member

It's set here to match the scheme name: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs#L23
Needs an overload to set the display name.

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Yeah we don't have those overloads in the security layer right now, so you'd have to drop down and use the lower overload to tweak the display name

@kevinchalet
Copy link
Contributor

If you decide to fix that in 2.0 (and I personally hope you will), please also fix aspnet/IISIntegration#391 (I'm fine submitting a PR if you prefer).

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Doubt we are doing that now, since its a non breaking change in 2.1

You can probably workaround this via directly tweaking the DisplayName via AuthenticationOptions.SchemeMap:

services.Configure<AuthenticationOptions>(o => o.SchemeMap["OIDC"].DisplayName = whatever

@leastprivilege
Copy link
Contributor Author

That's ridiculous.

@kevinchalet
Copy link
Contributor

Doubt we are doing that now, since its a non breaking change in 2.1

Well, it automatically means waiting maybe 5 or 6 months more before moving to 2.x.
And while you can indeed work around this limitation with the "classical" handlers, it's not possible with the host handlers.

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

What are you trying to do with display name that is so critical? Check if its null?

@kevinchalet
Copy link
Contributor

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

So you can just write your own filtering for which handlers to display for the external schemes, you don't have to use DisplayName != null as your condition. Why don't you just merge the list you have with the Windows scheme?

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

You are able to inspect the schemes yourself via IAuthenticationSchemeProvider, just compute the display list using that directly...

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Its up to the app to decide which schemes are appropriate anyways, we wrote some sugar (that I think lives in Identity?) that filters the schemes using DisplayName != null, but its just sugar

@kevinchalet
Copy link
Contributor

Sure, why not reinventing the wheel and using a hardcoded display name in your views when you could simply rely on SignInManager.GetExternalAuthenticationSchemesAsync(), that does the right thing for you and is used in the default templates...

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Well, you can just wait til 2.1 as you said if you prefer that instead of using the workaround

@kevinchalet
Copy link
Contributor

@HaoK maybe I wasn't clear enough: you CAN'T use the workaround you suggested with the host handlers due to the way you've decided to register them (in the IIS middleware constructor... dynamically :trollface:).

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

The sugar is not meant to the final arbiter of what schemes should be displayed, that is template sugar for the Individual auth template basically. I never liked having that in the framework, but it is what it is. External clearly doesn't hosts as written either.

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

The workaround for your case is to not use GetExternalAuthenticationSchemesAsync and compute that list yourself.

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Again, all that method does is:

var schemes = await _schemes.GetAllSchemesAsync();
return schemes.Where(s => !string.IsNullOrEmpty(s.DisplayName));

You really don't gain very much by calling it :p

@kevinchalet
Copy link
Contributor

Okay so @leastprivilege was right. Arguing so hard for a zero-risk change that will take 10 minutes to do is truly ridiculous.

@kevinchalet
Copy link
Contributor

You really don't gain very much by calling it :p

That's not the problem. The problem is that you can't use await _schemes.GetAllSchemesAsync(); as the display name will always be null. You'll have to hardcode it or import it from somewhere else, which makes no sense.

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Doesn't matter how long the fix takes, bar is higher than this bug, shipstoppers only.

@kevinchalet
Copy link
Contributor

Updating the display name associated with the host handlers was possible in 1.x. Since it's no longer possible in 2.x, that's a regression. Does that qualify as a shipstopper? :trollface:

services.Configure<IISOptions>(options =>
{
    options.AuthenticationDescriptions.Clear();

    options.AuthenticationDescriptions.Add(new AuthenticationDescription
    {
        AuthenticationScheme = IISDefaults.Negotiate,
        DisplayName = "Intranet"
    });

    options.AutomaticAuthentication = false;
});

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Most apps do not have a dynamic list of schemes, most have a couple of schemes they want to show, it really doesn't seem the end of the world for them to either:

  • use the sugar, and tweak (hardcode "Windows" in your case).
  • Or hardcode the entire list you return

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

If there was no way for you to workaround this in your app, you'd have a stronger argument :)

@kevinchalet
Copy link
Contributor

kevinchalet commented Jul 13, 2017

Most apps do not have a dynamic list of schemes, most have a couple of schemes they want to show

Then you should strongly consider revisiting how you handle that in 2.x/3.x because even if you don't like it, setting the display name in the options and using SignInManager.GetExternalAuthenticationSchemesAsync() was - and still is - the "official" way to do that.

But okay, point taken. I'll send a PR against the release branch as suggested by @Tratcher and try to bribe the guy in charge of approving the late PRs... :trollface:

@HaoK
Copy link
Member

HaoK commented Jul 13, 2017

Yeah this is a case of sugar overload in my mind. Those 2 lines should have just lived in the app, I tried to get rid of the concept entirely of DisplayName, but we couldn't come up with anything better, and we just ran out of time to spend on it so we brought it back late in preview 2 for the templates

@Tratcher Tratcher self-assigned this Jul 13, 2017
@Tratcher Tratcher added the bug label Jul 13, 2017
@Tratcher Tratcher added this to the 2.0.0 milestone Jul 13, 2017
Tratcher added a commit that referenced this issue Jul 13, 2017
Tratcher added a commit that referenced this issue Jul 13, 2017
Tratcher added a commit that referenced this issue Jul 13, 2017
Tratcher added a commit that referenced this issue Jul 13, 2017
Tratcher added a commit that referenced this issue Jul 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants