Rename ExternalAuthenticationOptions => Shared

This commit is contained in:
Hao Kung 2015-07-16 12:43:03 -07:00
parent 73d4440a25
commit 5a2499eb22
17 changed files with 44 additions and 30 deletions

View File

@ -15,7 +15,7 @@ namespace OpenIdConnectSample
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}); });

View File

@ -22,7 +22,7 @@ namespace CookieSample
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}); });

View File

@ -21,19 +21,22 @@ namespace Microsoft.AspNet.Authentication.Facebook
/// <summary> /// <summary>
/// Initializes a new <see cref="FacebookAuthenticationMiddleware"/>. /// Initializes a new <see cref="FacebookAuthenticationMiddleware"/>.
/// </summary> /// </summary>
/// <param name="next">The next middleware in the application pipeline to invoke.</param> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
/// <param name="dataProtectionProvider"></param> /// <param name="dataProtectionProvider"></param>
/// <param name="loggerFactory"></param> /// <param name="loggerFactory"></param>
/// <param name="encoder"></param>
/// <param name="sharedOptions"></param>
/// <param name="options">Configuration options for the middleware.</param> /// <param name="options">Configuration options for the middleware.</param>
/// <param name="configureOptions"></param>
public FacebookAuthenticationMiddleware( public FacebookAuthenticationMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<FacebookAuthenticationOptions> options, [NotNull] IOptions<FacebookAuthenticationOptions> options,
ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null) ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
{ {
if (string.IsNullOrWhiteSpace(Options.AppId)) if (string.IsNullOrWhiteSpace(Options.AppId))
{ {

View File

@ -24,16 +24,19 @@ namespace Microsoft.AspNet.Authentication.Google
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
/// <param name="dataProtectionProvider"></param> /// <param name="dataProtectionProvider"></param>
/// <param name="loggerFactory"></param> /// <param name="loggerFactory"></param>
/// <param name="encoder"></param>
/// <param name="sharedOptions"></param>
/// <param name="options">Configuration options for the middleware.</param> /// <param name="options">Configuration options for the middleware.</param>
/// <param name="configureOptions"></param>
public GoogleAuthenticationMiddleware( public GoogleAuthenticationMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<GoogleAuthenticationOptions> options, [NotNull] IOptions<GoogleAuthenticationOptions> options,
ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null) ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
{ {
if (Options.Scope.Count == 0) if (Options.Scope.Count == 0)
{ {

View File

@ -22,16 +22,19 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
/// <param name="dataProtectionProvider"></param> /// <param name="dataProtectionProvider"></param>
/// <param name="loggerFactory"></param> /// <param name="loggerFactory"></param>
/// <param name="encoder"></param>
/// <param name="sharedOptions"></param>
/// <param name="options">Configuration options for the middleware.</param> /// <param name="options">Configuration options for the middleware.</param>
/// <param name="configureOptions"></param>
public MicrosoftAccountAuthenticationMiddleware( public MicrosoftAccountAuthenticationMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<MicrosoftAccountAuthenticationOptions> options, [NotNull] IOptions<MicrosoftAccountAuthenticationOptions> options,
ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null) ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
: base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
{ {
if (Options.Scope.Count == 0) if (Options.Scope.Count == 0)
{ {

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
[NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<TOptions> options, [NotNull] IOptions<TOptions> options,
ConfigureOptions<TOptions> configureOptions = null) ConfigureOptions<TOptions> configureOptions = null)
: base(next, options, loggerFactory, encoder, configureOptions) : base(next, options, loggerFactory, encoder, configureOptions)
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
if (string.IsNullOrEmpty(Options.SignInScheme)) if (string.IsNullOrEmpty(Options.SignInScheme))
{ {
Options.SignInScheme = externalOptions.Options.SignInScheme; Options.SignInScheme = sharedOptions.Options.SignInScheme;
} }
} }

View File

@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
/// Gets or sets the authentication scheme corresponding to the middleware /// Gets or sets the authentication scheme corresponding to the middleware
/// responsible of persisting user's identity after a successful authentication. /// responsible of persisting user's identity after a successful authentication.
/// This value typically corresponds to a cookie middleware registered in the Startup class. /// This value typically corresponds to a cookie middleware registered in the Startup class.
/// When omitted, <see cref="ExternalAuthenticationOptions.SignInScheme"/> is used as a fallback value. /// When omitted, <see cref="SharedAuthenticationOptions.SignInScheme"/> is used as a fallback value.
/// </summary> /// </summary>
public string SignInScheme { get; set; } public string SignInScheme { get; set; }

View File

@ -31,6 +31,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
/// <param name="next">The next middleware in the ASP.NET pipeline to invoke.</param> /// <param name="next">The next middleware in the ASP.NET pipeline to invoke.</param>
/// <param name="dataProtectionProvider"> provider for creating a data protector.</param> /// <param name="dataProtectionProvider"> provider for creating a data protector.</param>
/// <param name="loggerFactory">factory for creating a <see cref="ILogger"/>.</param> /// <param name="loggerFactory">factory for creating a <see cref="ILogger"/>.</param>
/// <param name="encoder"></param>
/// <param name="services"></param>
/// <param name="sharedOptions"></param>
/// <param name="options">a <see cref="IOptions{OpenIdConnectAuthenticationOptions}"/> instance that will supply <see cref="OpenIdConnectAuthenticationOptions"/> /// <param name="options">a <see cref="IOptions{OpenIdConnectAuthenticationOptions}"/> instance that will supply <see cref="OpenIdConnectAuthenticationOptions"/>
/// if configureOptions is null.</param> /// if configureOptions is null.</param>
/// <param name="configureOptions">a <see cref="ConfigureOptions{OpenIdConnectAuthenticationOptions}"/> instance that will be passed to an instance of <see cref="OpenIdConnectAuthenticationOptions"/> /// <param name="configureOptions">a <see cref="ConfigureOptions{OpenIdConnectAuthenticationOptions}"/> instance that will be passed to an instance of <see cref="OpenIdConnectAuthenticationOptions"/>
@ -42,14 +45,14 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IServiceProvider services, [NotNull] IServiceProvider services,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<OpenIdConnectAuthenticationOptions> options, [NotNull] IOptions<OpenIdConnectAuthenticationOptions> options,
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null) ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null)
: base(next, options, loggerFactory, encoder, configureOptions) : base(next, options, loggerFactory, encoder, configureOptions)
{ {
if (string.IsNullOrEmpty(Options.SignInScheme) && !string.IsNullOrEmpty(externalOptions.Options.SignInScheme)) if (string.IsNullOrEmpty(Options.SignInScheme) && !string.IsNullOrEmpty(sharedOptions.Options.SignInScheme))
{ {
Options.SignInScheme = externalOptions.Options.SignInScheme; Options.SignInScheme = sharedOptions.Options.SignInScheme;
} }
if (Options.StateDataFormat == null) if (Options.StateDataFormat == null)

View File

@ -26,16 +26,18 @@ namespace Microsoft.AspNet.Authentication.Twitter
/// Initializes a <see cref="TwitterAuthenticationMiddleware"/> /// Initializes a <see cref="TwitterAuthenticationMiddleware"/>
/// </summary> /// </summary>
/// <param name="next">The next middleware in the HTTP pipeline to invoke</param> /// <param name="next">The next middleware in the HTTP pipeline to invoke</param>
/// <param name="services"></param>
/// <param name="dataProtectionProvider"></param> /// <param name="dataProtectionProvider"></param>
/// <param name="loggerFactory"></param> /// <param name="loggerFactory"></param>
/// <param name="encoder"></param>
/// <param name="sharedOptions"></param>
/// <param name="options">Configuration options for the middleware</param> /// <param name="options">Configuration options for the middleware</param>
/// <param name="configureOptions"></param>
public TwitterAuthenticationMiddleware( public TwitterAuthenticationMiddleware(
[NotNull] RequestDelegate next, [NotNull] RequestDelegate next,
[NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] ILoggerFactory loggerFactory, [NotNull] ILoggerFactory loggerFactory,
[NotNull] IUrlEncoder encoder, [NotNull] IUrlEncoder encoder,
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions, [NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
[NotNull] IOptions<TwitterAuthenticationOptions> options, [NotNull] IOptions<TwitterAuthenticationOptions> options,
ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null) ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
: base(next, options, loggerFactory, encoder, configureOptions) : base(next, options, loggerFactory, encoder, configureOptions)
@ -55,7 +57,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
} }
if (Options.StateDataFormat == null) if (Options.StateDataFormat == null)
{ {
IDataProtector dataProtector = dataProtectionProvider.CreateProtector( var dataProtector = dataProtectionProvider.CreateProtector(
typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v1"); typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v1");
Options.StateDataFormat = new SecureDataFormat<RequestToken>( Options.StateDataFormat = new SecureDataFormat<RequestToken>(
Serializers.RequestToken, Serializers.RequestToken,
@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
if (string.IsNullOrEmpty(Options.SignInScheme)) if (string.IsNullOrEmpty(Options.SignInScheme))
{ {
Options.SignInScheme = externalOptions.Options.SignInScheme; Options.SignInScheme = sharedOptions.Options.SignInScheme;
} }
if (string.IsNullOrEmpty(Options.SignInScheme)) if (string.IsNullOrEmpty(Options.SignInScheme))
{ {
@ -92,7 +94,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")] [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")]
private static HttpMessageHandler ResolveHttpMessageHandler(TwitterAuthenticationOptions options) private static HttpMessageHandler ResolveHttpMessageHandler(TwitterAuthenticationOptions options)
{ {
HttpMessageHandler handler = options.BackchannelHttpHandler ?? var handler = options.BackchannelHttpHandler ??
#if DNX451 #if DNX451
new WebRequestHandler(); new WebRequestHandler();
// If they provided a validator, apply it or fail. // If they provided a validator, apply it or fail.

View File

@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
/// Gets or sets the authentication scheme corresponding to the middleware /// Gets or sets the authentication scheme corresponding to the middleware
/// responsible of persisting user's identity after a successful authentication. /// responsible of persisting user's identity after a successful authentication.
/// This value typically corresponds to a cookie middleware registered in the Startup class. /// This value typically corresponds to a cookie middleware registered in the Startup class.
/// When omitted, <see cref="ExternalAuthenticationOptions.SignInScheme"/> is used as a fallback value. /// When omitted, <see cref="SharedAuthenticationOptions.SignInScheme"/> is used as a fallback value.
/// </summary> /// </summary>
public string SignInScheme { get; set; } public string SignInScheme { get; set; }

View File

@ -6,7 +6,7 @@ using System;
namespace Microsoft.AspNet.Authentication namespace Microsoft.AspNet.Authentication
{ {
public class ExternalAuthenticationOptions public class SharedAuthenticationOptions
{ {
/// <summary> /// <summary>
/// Gets or sets the authentication scheme corresponding to the default middleware /// Gets or sets the authentication scheme corresponding to the default middleware

View File

@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
options.AuthenticationScheme = "External"; options.AuthenticationScheme = "External";
options.AutomaticAuthentication = true; options.AutomaticAuthentication = true;
}); });
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = "External"; options.SignInScheme = "External";
}); });
@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
{ {
options.AuthenticationScheme = "External"; options.AuthenticationScheme = "External";
}); });
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = "External"; options.SignInScheme = "External";
}); });

View File

@ -601,7 +601,7 @@ namespace Microsoft.AspNet.Authentication.Google
services => services =>
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = TestExtensions.CookieAuthenticationScheme; options.SignInScheme = TestExtensions.CookieAuthenticationScheme;
}); });

View File

@ -218,7 +218,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
services => services =>
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = TestExtensions.CookieAuthenticationScheme; options.SignInScheme = TestExtensions.CookieAuthenticationScheme;
}); });

View File

@ -26,12 +26,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IUrlEncoder encoder, IUrlEncoder encoder,
IServiceProvider services, IServiceProvider services,
IOptions<ExternalAuthenticationOptions> externalOptions, IOptions<SharedAuthenticationOptions> sharedOptions,
IOptions<OpenIdConnectAuthenticationOptions> options, IOptions<OpenIdConnectAuthenticationOptions> options,
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null, ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null,
OpenIdConnectAuthenticationHandler handler = null OpenIdConnectAuthenticationHandler handler = null
) )
: base(next, dataProtectionProvider, loggerFactory, encoder, services, externalOptions, options, configureOptions) : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, configureOptions)
{ {
_handler = handler; _handler = handler;
var customFactory = loggerFactory as InMemoryLoggerFactory; var customFactory = loggerFactory as InMemoryLoggerFactory;

View File

@ -366,7 +366,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
services => services =>
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}); });

View File

@ -171,7 +171,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
services => services =>
{ {
services.AddAuthentication(); services.AddAuthentication();
services.Configure<ExternalAuthenticationOptions>(options => services.Configure<SharedAuthenticationOptions>(options =>
{ {
options.SignInScheme = "External"; options.SignInScheme = "External";
}); });