Skip to content

Revert AuthenticationAddXyz overload changes #24125

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/Identity/Core/src/IdentityServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,6 @@ public static IdentityBuilder AddIdentity<TUser, TRole>(
public static IServiceCollection ConfigureApplicationCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
=> services.Configure(IdentityConstants.ApplicationScheme, configure);

/// <summary>
/// Configures the application cookie.
/// </summary>
/// <typeparam name="TService">TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly.</typeparam>
/// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns>
public static IServiceCollection ConfigureApplicationCookie<TService>(this IServiceCollection services, Action<CookieAuthenticationOptions, TService> configure) where TService : class
{
services.AddOptions<CookieAuthenticationOptions>(IdentityConstants.ApplicationScheme)
.Configure(configure);

return services;
}

/// <summary>
/// Configure the external cookie.
/// </summary>
Expand All @@ -133,20 +118,5 @@ public static IServiceCollection ConfigureApplicationCookie<TService>(this IServ
/// <returns>The services.</returns>
public static IServiceCollection ConfigureExternalCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
=> services.Configure(IdentityConstants.ExternalScheme, configure);

/// <summary>
/// Configure the external cookie.
/// </summary>
/// <typeparam name="TService">TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly.</typeparam>
/// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns>
public static IServiceCollection ConfigureExternalCookie<TService>(this IServiceCollection services, Action<CookieAuthenticationOptions, TService> configure) where TService : class
{
services.AddOptions<CookieAuthenticationOptions>(IdentityConstants.ExternalScheme)
.Configure(configure);

return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder bu
/// <param name="authenticationScheme"></param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder builder, string authenticationScheme)
=> builder.AddCertificate(authenticationScheme, configureOptions: (Action<CertificateAuthenticationOptions, IServiceProvider>)null);
=> builder.AddCertificate(authenticationScheme, configureOptions: null);

/// <summary>
/// Adds certificate authentication.
Expand All @@ -39,16 +39,6 @@ public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder bu
public static AuthenticationBuilder AddCertificate(this AuthenticationBuilder builder, Action<CertificateAuthenticationOptions> configureOptions)
=> builder.AddCertificate(CertificateAuthenticationDefaults.AuthenticationScheme, configureOptions);

/// <summary>
/// Adds certificate authentication.
/// </summary>
/// <typeparam name="TService">TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly.</typeparam>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <param name="configureOptions"></param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddCertificate<TService>(this AuthenticationBuilder builder, Action<CertificateAuthenticationOptions, TService> configureOptions) where TService : class
=> builder.AddCertificate(CertificateAuthenticationDefaults.AuthenticationScheme, configureOptions);

/// <summary>
/// Adds certificate authentication.
/// </summary>
Expand All @@ -60,33 +50,7 @@ public static AuthenticationBuilder AddCertificate(
this AuthenticationBuilder builder,
string authenticationScheme,
Action<CertificateAuthenticationOptions> configureOptions)
{
Action<CertificateAuthenticationOptions, IServiceProvider> configureOptionsWithServices;
if (configureOptions == null)
{
configureOptionsWithServices = null;
}
else
{
configureOptionsWithServices = (options, _) => configureOptions(options);
}

return builder.AddCertificate(authenticationScheme, configureOptionsWithServices);
}

/// <summary>
/// Adds certificate authentication.
/// </summary>
/// <typeparam name="TService">TService: A service resolved from the IServiceProvider for use when configuring this authentication provider. If you need multiple services then specify IServiceProvider and resolve them directly.</typeparam>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <param name="authenticationScheme"></param>
/// <param name="configureOptions"></param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddCertificate<TService>(
this AuthenticationBuilder builder,
string authenticationScheme,
Action<CertificateAuthenticationOptions, TService> configureOptions) where TService : class
=> builder.AddScheme<CertificateAuthenticationOptions, CertificateAuthenticationHandler, TService>(authenticationScheme, configureOptions);
=> builder.AddScheme<CertificateAuthenticationOptions, CertificateAuthenticationHandler>(authenticationScheme, configureOptions);

/// <summary>
/// Adds certificate authentication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<MemoryCacheTicketStore>();

// This can be removed after https://github.com/aspnet/IISIntegration/issues/371
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie<MemoryCacheTicketStore>((o, ticketStore) => o.SessionStore = ticketStore);
}).AddCookie();

services.AddOptions<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme)
.Configure<MemoryCacheTicketStore>((o, ticketStore) => o.SessionStore = ticketStore);
}

public void Configure(IApplicationBuilder app)
Expand Down
27 changes: 3 additions & 24 deletions src/Security/Authentication/Cookies/src/CookieExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,19 @@ public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder
=> builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);

public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme)
=> builder.AddCookie(authenticationScheme, configureOptions: (Action<CookieAuthenticationOptions, IServiceProvider>)null);
=> builder.AddCookie(authenticationScheme, configureOptions: null);

public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, Action<CookieAuthenticationOptions> configureOptions)
=> builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions);

public static AuthenticationBuilder AddCookie<TService>(this AuthenticationBuilder builder, Action<CookieAuthenticationOptions, TService> configureOptions) where TService : class
public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, Action<CookieAuthenticationOptions> configureOptions)
=> builder.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, configureOptions);

public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, Action<CookieAuthenticationOptions> configureOptions)
=> builder.AddCookie(authenticationScheme, displayName: null, configureOptions: configureOptions);

public static AuthenticationBuilder AddCookie<TService>(this AuthenticationBuilder builder, string authenticationScheme, Action<CookieAuthenticationOptions, TService> configureOptions) where TService : class
=> builder.AddCookie(authenticationScheme, displayName: null, configureOptions: configureOptions);

public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<CookieAuthenticationOptions> configureOptions)
{
Action<CookieAuthenticationOptions, IServiceProvider> configureOptionsWithServices;
if (configureOptions == null)
{
configureOptionsWithServices = null;
}
else
{
configureOptionsWithServices = (options, _) => configureOptions(options);
}

return builder.AddCookie(authenticationScheme, displayName, configureOptionsWithServices);
}

public static AuthenticationBuilder AddCookie<TService>(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<CookieAuthenticationOptions, TService> configureOptions) where TService : class
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<CookieAuthenticationOptions>, PostConfigureCookieAuthenticationOptions>());
builder.Services.AddOptions<CookieAuthenticationOptions>(authenticationScheme).Validate(o => o.Cookie.Expiration == null, "Cookie.Expiration is ignored, use ExpireTimeSpan instead.");
return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler, TService>(authenticationScheme, displayName, configureOptions);
return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, displayName, configureOptions);
}
}
}
Loading