React to Options and Hosting changes

This commit is contained in:
Hao Kung 2014-10-14 19:14:54 -07:00
parent 6965a66f18
commit 84dfcf5258
23 changed files with 47 additions and 47 deletions

View File

@ -9,7 +9,7 @@ namespace CookieSample
{ {
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UsePerRequestServices(services => { }); app.UseServices(services => { });
app.UseCookieAuthentication(options => app.UseCookieAuthentication(options =>
{ {
}); });

View File

@ -10,7 +10,7 @@ namespace CookieSessionSample
{ {
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UsePerRequestServices(services => { }); app.UseServices(services => { });
app.UseCookieAuthentication(options => app.UseCookieAuthentication(options =>
{ {
options.SessionStore = new MemoryCacheSessionStore(); options.SessionStore = new MemoryCacheSessionStore();

View File

@ -24,7 +24,7 @@ namespace CookieSample
{ {
app.UseErrorPage(); app.UseErrorPage();
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.ConfigureOptions<ExternalAuthenticationOptions>(options =>
{ {

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder
{ {
public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<CookieAuthenticationOptions> configure) public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<CookieAuthenticationOptions> configure)
{ {
return services.ConfigureOptions(configure); return services.Configure(configure);
} }
/// <summary> /// <summary>
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action<CookieAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action<CookieAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<CookieAuthenticationMiddleware>( return app.UseMiddleware<CookieAuthenticationMiddleware>(
new OptionsAction<CookieAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<CookieAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -20,8 +20,8 @@ namespace Microsoft.AspNet.Security.Cookies
public CookieAuthenticationMiddleware(RequestDelegate next, public CookieAuthenticationMiddleware(RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<CookieAuthenticationOptions> options, IOptions<CookieAuthenticationOptions> options,
IOptionsAction<CookieAuthenticationOptions> configureOptions) ConfigureOptions<CookieAuthenticationOptions> configureOptions)
: base(next, options, configureOptions) : base(next, options, configureOptions)
{ {
if (Options.Notifications == null) if (Options.Notifications == null)

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder
{ {
public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> configure) public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> configure)
{ {
return services.ConfigureOptions(configure); return services.Configure(configure);
} }
/// <summary> /// <summary>
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<FacebookAuthenticationMiddleware>( return app.UseMiddleware<FacebookAuthenticationMiddleware>(
new OptionsAction<FacebookAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<FacebookAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -28,9 +28,9 @@ namespace Microsoft.AspNet.Security.Facebook
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<ExternalAuthenticationOptions> externalOptions, IOptions<ExternalAuthenticationOptions> externalOptions,
IOptionsAccessor<FacebookAuthenticationOptions> options, IOptions<FacebookAuthenticationOptions> options,
IOptionsAction<FacebookAuthenticationOptions> configureOptions = null) ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
{ {
if (string.IsNullOrWhiteSpace(Options.AppId)) if (string.IsNullOrWhiteSpace(Options.AppId))

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder
{ {
public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> configure) public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> configure)
{ {
return services.ConfigureOptions(configure); return services.Configure(configure);
} }
/// <summary> /// <summary>
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action<GoogleAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action<GoogleAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<GoogleAuthenticationMiddleware>( return app.UseMiddleware<GoogleAuthenticationMiddleware>(
new OptionsAction<GoogleAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<GoogleAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -32,9 +32,9 @@ namespace Microsoft.AspNet.Security.Google
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<ExternalAuthenticationOptions> externalOptions, IOptions<ExternalAuthenticationOptions> externalOptions,
IOptionsAccessor<GoogleAuthenticationOptions> options, IOptions<GoogleAuthenticationOptions> options,
IOptionsAction<GoogleAuthenticationOptions> configureOptions = null) ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
{ {
if (Options.Notifications == null) if (Options.Notifications == null)

View File

@ -15,13 +15,13 @@ namespace Microsoft.AspNet.Builder
{ {
public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> configure) public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> configure)
{ {
return services.ConfigureOptions(configure); return services.Configure(configure);
} }
public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<MicrosoftAccountAuthenticationMiddleware>( return app.UseMiddleware<MicrosoftAccountAuthenticationMiddleware>(
new OptionsAction<MicrosoftAccountAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<MicrosoftAccountAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -28,9 +28,9 @@ namespace Microsoft.AspNet.Security.MicrosoftAccount
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<ExternalAuthenticationOptions> externalOptions, IOptions<ExternalAuthenticationOptions> externalOptions,
IOptionsAccessor<MicrosoftAccountAuthenticationOptions> options, IOptions<MicrosoftAccountAuthenticationOptions> options,
IOptionsAction<MicrosoftAccountAuthenticationOptions> configureOptions = null) ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
{ {
if (Options.Notifications == null) if (Options.Notifications == null)

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] string authenticationType, Action<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>> configureOptions = null) public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] string authenticationType, Action<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>> configureOptions = null)
{ {
return app.UseMiddleware<OAuthAuthenticationMiddleware<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>, IOAuthAuthenticationNotifications>>( return app.UseMiddleware<OAuthAuthenticationMiddleware<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>, IOAuthAuthenticationNotifications>>(
new OptionsAction<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>>(options => new ConfigureOptions<OAuthAuthenticationOptions<IOAuthAuthenticationNotifications>>(options =>
{ {
options.AuthenticationType = authenticationType; options.AuthenticationType = authenticationType;
options.Caption = authenticationType; options.Caption = authenticationType;

View File

@ -33,9 +33,9 @@ namespace Microsoft.AspNet.Security.OAuth
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<ExternalAuthenticationOptions> externalOptions, IOptions<ExternalAuthenticationOptions> externalOptions,
IOptionsAccessor<TOptions> options, IOptions<TOptions> options,
IOptionsAction<TOptions> configureOptions = null) ConfigureOptions<TOptions> configureOptions = null)
: base(next, options, configureOptions) : base(next, options, configureOptions)
{ {
// todo: review error handling // todo: review error handling

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseOAuthBearerAuthentication([NotNull] this IApplicationBuilder app, Action<OAuthBearerAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseOAuthBearerAuthentication([NotNull] this IApplicationBuilder app, Action<OAuthBearerAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<OAuthBearerAuthenticationMiddleware>( return app.UseMiddleware<OAuthBearerAuthenticationMiddleware>(
new OptionsAction<OAuthBearerAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<OAuthBearerAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -30,8 +30,8 @@ namespace Microsoft.AspNet.Security.OAuth
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<OAuthBearerAuthenticationOptions> options, IOptions<OAuthBearerAuthenticationOptions> options,
IOptionsAction<OAuthBearerAuthenticationOptions> configureOptions) ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
: base(next, options, configureOptions) : base(next, options, configureOptions)
{ {
_logger = loggerFactory.Create<OAuthBearerAuthenticationMiddleware>(); _logger = loggerFactory.Create<OAuthBearerAuthenticationMiddleware>();

View File

@ -16,13 +16,13 @@ namespace Microsoft.AspNet.Builder
{ {
public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> configure) public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> configure)
{ {
return services.ConfigureOptions(configure); return services.Configure(configure);
} }
public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterAuthenticationOptions> configureOptions = null, string optionsName = "") public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterAuthenticationOptions> configureOptions = null, string optionsName = "")
{ {
return app.UseMiddleware<TwitterAuthenticationMiddleware>( return app.UseMiddleware<TwitterAuthenticationMiddleware>(
new OptionsAction<TwitterAuthenticationOptions>(configureOptions ?? (o => { })) new ConfigureOptions<TwitterAuthenticationOptions>(configureOptions ?? (o => { }))
{ {
Name = optionsName Name = optionsName
}); });

View File

@ -36,9 +36,9 @@ namespace Microsoft.AspNet.Security.Twitter
RequestDelegate next, RequestDelegate next,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptionsAccessor<ExternalAuthenticationOptions> externalOptions, IOptions<ExternalAuthenticationOptions> externalOptions,
IOptionsAccessor<TwitterAuthenticationOptions> options, IOptions<TwitterAuthenticationOptions> options,
IOptionsAction<TwitterAuthenticationOptions> configureOptions = null) ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
: base(next, options, configureOptions) : base(next, options, configureOptions)
{ {
if (string.IsNullOrWhiteSpace(Options.ConsumerSecret)) if (string.IsNullOrWhiteSpace(Options.ConsumerSecret))

View File

@ -14,12 +14,12 @@ namespace Microsoft.AspNet.Security.Infrastructure
{ {
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IOptionsAccessor<TOptions> options, IOptionsAction<TOptions> configureOptions) protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IOptions<TOptions> options, ConfigureOptions<TOptions> configureOptions)
{ {
if (configureOptions != null) if (configureOptions != null)
{ {
Options = options.GetNamedOptions(configureOptions.Name); Options = options.GetNamedOptions(configureOptions.Name);
configureOptions.Invoke(Options); configureOptions.Configure(Options, configureOptions.Name);
} }
else else
{ {

View File

@ -369,7 +369,7 @@ namespace Microsoft.AspNet.Security.Cookies
{ {
return TestServer.Create(app => return TestServer.Create(app =>
{ {
app.UsePerRequestServices(services => { }); app.UseServices(services => { });
app.UseCookieAuthentication(configureOptions); app.UseCookieAuthentication(configureOptions);
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Security.Facebook
var server = CreateServer( var server = CreateServer(
app => app =>
{ {
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureFacebookAuthentication(options => services.ConfigureFacebookAuthentication(options =>
{ {
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Security.Facebook
{ {
options.AuthenticationType = "External"; options.AuthenticationType = "External";
}); });
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.Configure<ExternalAuthenticationOptions>(options =>
{ {
options.SignInAsAuthenticationType = "External"; options.SignInAsAuthenticationType = "External";
}); });
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Security.Facebook
var server = CreateServer( var server = CreateServer(
app => app =>
{ {
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureFacebookAuthentication(options => services.ConfigureFacebookAuthentication(options =>
{ {
@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Security.Facebook
{ {
options.AuthenticationType = "External"; options.AuthenticationType = "External";
}); });
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.Configure<ExternalAuthenticationOptions>(options =>
{ {
options.SignInAsAuthenticationType = "External"; options.SignInAsAuthenticationType = "External";
}); });

View File

@ -465,9 +465,9 @@ namespace Microsoft.AspNet.Security.Google
{ {
return TestServer.Create(app => return TestServer.Create(app =>
{ {
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.Configure<ExternalAuthenticationOptions>(options =>
{ {
options.SignInAsAuthenticationType = CookieAuthenticationType; options.SignInAsAuthenticationType = CookieAuthenticationType;
}); });

View File

@ -163,9 +163,9 @@ namespace Microsoft.AspNet.Security.Tests.MicrosoftAccount
{ {
return TestServer.Create(app => return TestServer.Create(app =>
{ {
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.Configure<ExternalAuthenticationOptions>(options =>
{ {
options.SignInAsAuthenticationType = "External"; options.SignInAsAuthenticationType = "External";
}); });

View File

@ -109,9 +109,9 @@ namespace Microsoft.AspNet.Security.Twitter
{ {
return TestServer.Create(app => return TestServer.Create(app =>
{ {
app.UsePerRequestServices(services => app.UseServices(services =>
{ {
services.ConfigureOptions<ExternalAuthenticationOptions>(options => services.Configure<ExternalAuthenticationOptions>(options =>
{ {
options.SignInAsAuthenticationType = "External"; options.SignInAsAuthenticationType = "External";
}); });