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

Commit 4f20655

Browse files
committed
Set DisplayName for auth
1 parent 7fd15a2 commit 4f20655

File tree

16 files changed

+100
-10
lines changed

16 files changed

+100
-10
lines changed

samples/SocialSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
238238
foreach (var provider in await schemeProvider.GetAllSchemesAsync())
239239
{
240240
// REVIEW: we lost access to display name (which is buried in the handler options)
241-
await context.Response.WriteAsync("<a href=\"?authscheme=" + provider.Name + "\">" + (provider.Name ?? "(suppressed)") + "</a><br>");
241+
await context.Response.WriteAsync("<a href=\"?authscheme=" + provider.Name + "\">" + (provider.DisplayName ?? "(suppressed)") + "</a><br>");
242242
}
243243
await context.Response.WriteAsync("</body></html>");
244244
});

src/Microsoft.AspNetCore.Authentication.Facebook/FacebookExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddFacebookAuthentication(this IServiceCollecti
2626

2727
public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, string authenticationScheme, Action<FacebookOptions> configureOptions)
2828
{
29-
return services.AddScheme<FacebookOptions, FacebookHandler>(authenticationScheme, configureOptions);
29+
return services.AddScheme<FacebookOptions, FacebookHandler>(authenticationScheme, authenticationScheme, configureOptions);
3030
}
3131
}
3232
}

src/Microsoft.AspNetCore.Authentication.Google/GoogleExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddGoogleAuthentication(this IServiceCollection
2626

2727
public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, string authenticationScheme, Action<GoogleOptions> configureOptions)
2828
{
29-
return services.AddScheme<GoogleOptions, GoogleHandler>(authenticationScheme, configureOptions);
29+
return services.AddScheme<GoogleOptions, GoogleHandler>(authenticationScheme, authenticationScheme, configureOptions);
3030
}
3131
}
3232
}

src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddMicrosoftAccountAuthentication(this IService
2626

2727
public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, string authenticationScheme, Action<MicrosoftAccountOptions> configureOptions)
2828
{
29-
return services.AddScheme<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, configureOptions);
29+
return services.AddScheme<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, authenticationScheme, configureOptions);
3030
}
3131
}
3232
}

src/Microsoft.AspNetCore.Authentication.OAuth/OAuthExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ namespace Microsoft.AspNetCore.Builder
1010
public static class OAuthExtensions
1111
{
1212
public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action<OAuthOptions> configureOptions) =>
13-
services.AddScheme<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, configureOptions);
13+
services.AddScheme<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, authenticationScheme, configureOptions);
1414
}
1515
}

src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCol
2626

2727
public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, string authenticationScheme, Action<OpenIdConnectOptions> configureOptions)
2828
{
29-
return services.AddScheme<OpenIdConnectOptions, OpenIdConnectHandler>(authenticationScheme, configureOptions);
29+
return services.AddScheme<OpenIdConnectOptions, OpenIdConnectHandler>(authenticationScheme, authenticationScheme, configureOptions);
3030
}
3131
}
3232
}

src/Microsoft.AspNetCore.Authentication.Twitter/TwitterExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddTwitterAuthentication(this IServiceCollectio
2626

2727
public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, string authenticationScheme, Action<TwitterOptions> configureOptions)
2828
{
29-
return services.AddScheme<TwitterOptions, TwitterHandler>(authenticationScheme, configureOptions);
29+
return services.AddScheme<TwitterOptions, TwitterHandler>(authenticationScheme, authenticationScheme, configureOptions);
3030
}
3131
}
3232
}

src/Microsoft.AspNetCore.Authentication/AuthenticationServiceCollectionExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ public static IServiceCollection AddAuthentication(this IServiceCollection servi
4545
return services;
4646
}
4747

48-
public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<AuthenticationSchemeBuilder> configureScheme, Action<TOptions> configureOptions)
48+
public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, string displayName, Action<AuthenticationSchemeBuilder> configureScheme, Action<TOptions> configureOptions)
4949
where TOptions : AuthenticationSchemeOptions, new()
5050
where THandler : AuthenticationHandler<TOptions>
5151
{
5252
services.AddAuthentication(o =>
5353
{
5454
o.AddScheme(authenticationScheme, scheme => {
5555
scheme.HandlerType = typeof(THandler);
56+
scheme.DisplayName = displayName;
5657
configureScheme?.Invoke(scheme);
5758
});
5859
});
@@ -67,6 +68,11 @@ public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceColl
6768
public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<TOptions> configureOptions)
6869
where TOptions : AuthenticationSchemeOptions, new()
6970
where THandler : AuthenticationHandler<TOptions>
70-
=> services.AddScheme<TOptions, THandler>(authenticationScheme, configureScheme: null, configureOptions: configureOptions);
71+
=> services.AddScheme<TOptions, THandler>(authenticationScheme, displayName: null, configureScheme: null, configureOptions: configureOptions);
72+
73+
public static IServiceCollection AddScheme<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, string displayName, Action<TOptions> configureOptions)
74+
where TOptions : AuthenticationSchemeOptions, new()
75+
where THandler : AuthenticationHandler<TOptions>
76+
=> services.AddScheme<TOptions, THandler>(authenticationScheme, displayName, configureScheme: null, configureOptions: configureOptions);
7177
}
7278
}

test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ public class CookieTests
2626
{
2727
private TestClock _clock = new TestClock();
2828

29+
[Fact]
30+
public async Task VerifySchemeDefaults()
31+
{
32+
var services = new ServiceCollection().AddCookieAuthentication();
33+
var sp = services.BuildServiceProvider();
34+
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
35+
var scheme = await schemeProvider.GetSchemeAsync(CookieAuthenticationDefaults.AuthenticationScheme);
36+
Assert.NotNull(scheme);
37+
Assert.Equal("CookieAuthenticationHandler", scheme.HandlerType.Name);
38+
Assert.Null(scheme.DisplayName);
39+
}
40+
2941
[Fact]
3042
public async Task NormalRequestPassesThrough()
3143
{

test/Microsoft.AspNetCore.Authentication.Test/DynamicSchemeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private static TestServer CreateServer(Action<AuthenticationOptions> configureAu
9999
{
100100
var name = remainder.Value.Substring(1);
101101
var auth = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>();
102-
var scheme = new AuthenticationScheme(name, typeof(TestHandler));
102+
var scheme = new AuthenticationScheme(name, name, typeof(TestHandler));
103103
auth.AddScheme(scheme);
104104
}
105105
else if (req.Path.StartsWithSegments(new PathString("/auth"), out remainder))

0 commit comments

Comments
 (0)