Remove AddXyzAuth extension methods

This commit is contained in:
Hao Kung 2017-07-03 12:56:39 -07:00 committed by Hao Kung
parent a7bf561b1c
commit 1c30f33c92
15 changed files with 22 additions and 126 deletions

View File

@ -25,20 +25,5 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>());
return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, configureOptions);
}
// REMOVE below once callers have been updated
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services) => services.AddCookieAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, string authenticationScheme) => services.AddCookieAuthentication(authenticationScheme, configureOptions: null);
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, Action<CookieAuthenticationOptions> configureOptions) =>
services.AddCookieAuthentication(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, string authenticationScheme, Action<CookieAuthenticationOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>());
return services.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, configureOptions);
}
}
}

View File

@ -17,16 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection
public static AuthenticationBuilder AddFacebook(this AuthenticationBuilder builder, string authenticationScheme, Action<FacebookOptions> configureOptions)
=> builder.AddOAuth<FacebookOptions, FacebookHandler>(authenticationScheme, configureOptions);
// REMOVE below once callers have been updated
public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services)
=> services.AddFacebookAuthentication(FacebookDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, Action<FacebookOptions> configureOptions)
=> services.AddFacebookAuthentication(FacebookDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddFacebookAuthentication(this IServiceCollection services, string authenticationScheme, Action<FacebookOptions> configureOptions)
=> services.AddOAuthAuthentication<FacebookOptions, FacebookHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -17,17 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection
public static AuthenticationBuilder AddGoogle(this AuthenticationBuilder builder, string authenticationScheme, Action<GoogleOptions> configureOptions)
=> builder.AddOAuth<GoogleOptions, GoogleHandler>(authenticationScheme, configureOptions);
// REMOVE below once callers have been updated
public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services)
=> services.AddGoogleAuthentication(GoogleDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, Action<GoogleOptions> configureOptions)
=> services.AddGoogleAuthentication(GoogleDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddGoogleAuthentication(this IServiceCollection services, string authenticationScheme, Action<GoogleOptions> configureOptions)
=> services.AddOAuthAuthentication<GoogleOptions, GoogleHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -22,19 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerPostConfigureOptions>());
return builder.AddScheme<JwtBearerOptions, JwtBearerHandler>(authenticationScheme, configureOptions);
}
// REMOVE once callers updated
public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services)
=> services.AddJwtBearerAuthentication(JwtBearerDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, Action<JwtBearerOptions> configureOptions)
=> services.AddJwtBearerAuthentication(JwtBearerDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddJwtBearerAuthentication(this IServiceCollection services, string authenticationScheme, Action<JwtBearerOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerPostConfigureOptions>());
return services.AddScheme<JwtBearerOptions, JwtBearerHandler>(authenticationScheme, configureOptions);
}
}
}

View File

@ -17,17 +17,5 @@ namespace Microsoft.Extensions.DependencyInjection
public static AuthenticationBuilder AddMicrosoftAccount(this AuthenticationBuilder builder, string authenticationScheme, Action<MicrosoftAccountOptions> configureOptions)
=> builder.AddOAuth<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, configureOptions);
// REMOVE below once callers have been updated
public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services)
=> services.AddMicrosoftAccountAuthentication(MicrosoftAccountDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, Action<MicrosoftAccountOptions> configureOptions)
=> services.AddMicrosoftAccountAuthentication(MicrosoftAccountDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddMicrosoftAccountAuthentication(this IServiceCollection services, string authenticationScheme, Action<MicrosoftAccountOptions> configureOptions)
=> services.AddOAuthAuthentication<MicrosoftAccountOptions, MicrosoftAccountHandler>(authenticationScheme, configureOptions);
}
}

View File

@ -21,19 +21,5 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TOptions>, OAuthPostConfigureOptions<TOptions, THandler>>());
return builder.AddRemoteScheme<TOptions, THandler>(authenticationScheme, authenticationScheme, configureOptions);
}
// REMOVE below once callers have been updated
public static IServiceCollection AddOAuthAuthentication(this IServiceCollection services, string authenticationScheme, Action<OAuthOptions> configureOptions)
{
return services.AddOAuthAuthentication<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, configureOptions);
}
public static IServiceCollection AddOAuthAuthentication<TOptions, THandler>(this IServiceCollection services, string authenticationScheme, Action<TOptions> configureOptions)
where TOptions : OAuthOptions, new()
where THandler : OAuthHandler<TOptions>
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TOptions>, OAuthPostConfigureOptions<TOptions, THandler>>());
return services.AddRemoteScheme<TOptions, THandler>(authenticationScheme, authenticationScheme, configureOptions);
}
}
}

View File

@ -22,18 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>());
return builder.AddRemoteScheme<OpenIdConnectOptions, OpenIdConnectHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
// REMOVE once callers have been updated
public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services)
=> services.AddOpenIdConnectAuthentication(OpenIdConnectDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, Action<OpenIdConnectOptions> configureOptions)
=> services.AddOpenIdConnectAuthentication(OpenIdConnectDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddOpenIdConnectAuthentication(this IServiceCollection services, string authenticationScheme, Action<OpenIdConnectOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>());
return services.AddRemoteScheme<OpenIdConnectOptions, OpenIdConnectHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
}
}

View File

@ -22,18 +22,5 @@ namespace Microsoft.Extensions.DependencyInjection
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TwitterOptions>, TwitterPostConfigureOptions>());
return builder.AddRemoteScheme<TwitterOptions, TwitterHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
// REMOVE below once callers have been updated.
public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services)
=> services.AddTwitterAuthentication(TwitterDefaults.AuthenticationScheme, _ => { });
public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, Action<TwitterOptions> configureOptions)
=> services.AddTwitterAuthentication(TwitterDefaults.AuthenticationScheme, configureOptions);
public static IServiceCollection AddTwitterAuthentication(this IServiceCollection services, string authenticationScheme, Action<TwitterOptions> configureOptions)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TwitterOptions>, TwitterPostConfigureOptions>());
return services.AddRemoteScheme<TwitterOptions, TwitterHandler>(authenticationScheme, authenticationScheme, configureOptions);
}
}
}

View File

@ -37,8 +37,6 @@ namespace Microsoft.AspNetCore.Authentication
OriginalPathBase = context.Request.PathBase
});
// REVIEW: alternatively could depend on a routing middleware to do this
// Give any IAuthenticationRequestHandler schemes a chance to handle the request
var handlers = context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
foreach (var scheme in await Schemes.GetRequestHandlerSchemesAsync())

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
@ -16,10 +15,8 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Xunit;
@ -30,7 +27,8 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddFacebookAuthentication().AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
var services = new ServiceCollection();
services.AddAuthentication().AddFacebook();
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync(FacebookDefaults.AuthenticationScheme);
@ -44,7 +42,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
{
var server = CreateServer(
app => { },
services => services.AddFacebookAuthentication(o => o.SignInScheme = "Whatever"),
services => services.AddAuthentication().AddFacebook(o => o.SignInScheme = "Whatever"),
context =>
{
// REVIEW: Gross.
@ -60,7 +58,7 @@ namespace Microsoft.AspNetCore.Authentication.Facebook
{
var server = CreateServer(
app => { },
services => services.AddFacebookAuthentication(o => o.AppId = "Whatever"),
services => services.AddAuthentication().AddFacebook(o => o.AppId = "Whatever"),
context =>
{
// REVIEW: Gross.

View File

@ -29,7 +29,8 @@ namespace Microsoft.AspNetCore.Authentication.Google
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddGoogleAuthentication().AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
var services = new ServiceCollection();
services.AddAuthentication().AddGoogle();
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync(GoogleDefaults.AuthenticationScheme);

View File

@ -29,7 +29,8 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddJwtBearerAuthentication().AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
var services = new ServiceCollection();
services.AddAuthentication().AddJwtBearer();
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync(JwtBearerDefaults.AuthenticationScheme);
@ -747,7 +748,7 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer
}
});
})
.ConfigureServices(services => services.AddJwtBearerAuthentication(options));
.ConfigureServices(services => services.AddAuthentication().AddJwtBearer(options));
return new TestServer(builder);
}

View File

@ -30,7 +30,8 @@ namespace Microsoft.AspNetCore.Authentication.Tests.MicrosoftAccount
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddMicrosoftAccountAuthentication().AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
var services = new ServiceCollection();
services.AddAuthentication().AddMicrosoftAccount();
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync(MicrosoftAccountDefaults.AuthenticationScheme);

View File

@ -19,7 +19,8 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddOAuthAuthentication("oauth", o => { });
var services = new ServiceCollection();
services.AddAuthentication().AddOAuth("oauth", o => { });
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync("oauth");
@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
services => services.AddOAuthAuthentication("weeblie", o =>
services => services.AddAuthentication().AddOAuth("weeblie", o =>
{
o.SignInScheme = "whatever";
o.CallbackPath = "/";
@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
services => services.AddOAuthAuthentication("weeblie", o =>
services => services.AddAuthentication().AddOAuth("weeblie", o =>
{
o.SignInScheme = "whatever";
o.ClientId = "Whatever;";
@ -79,7 +80,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
services => services.AddOAuthAuthentication("weeblie", o =>
services => services.AddAuthentication().AddOAuth("weeblie", o =>
{
o.ClientId = "Whatever;";
o.ClientSecret = "Whatever;";
@ -102,7 +103,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
services => services.AddOAuthAuthentication("weeblie", o =>
services => services.AddAuthentication().AddOAuth("weeblie", o =>
{
o.ClientId = "Whatever;";
o.ClientSecret = "Whatever;";
@ -125,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
services => services.AddOAuthAuthentication("weeblie", o =>
services => services.AddAuthentication().AddOAuth("weeblie", o =>
{
o.ClientId = "Whatever;";
o.ClientSecret = "Whatever;";
@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
s => s.AddOAuthAuthentication(
s => s.AddAuthentication().AddOAuth(
"Weblie",
opt =>
{
@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
{
var server = CreateServer(
app => { },
s => s.AddOAuthAuthentication(
s => s.AddAuthentication().AddOAuth(
"Weblie",
opt =>
{

View File

@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
@ -21,7 +20,8 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
[Fact]
public async Task VerifySchemeDefaults()
{
var services = new ServiceCollection().AddTwitterAuthentication().AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
var services = new ServiceCollection();
services.AddAuthentication().AddTwitter();
var sp = services.BuildServiceProvider();
var schemeProvider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await schemeProvider.GetSchemeAsync(TwitterDefaults.AuthenticationScheme);