From bf2b771eabcccfd6317e50366d4869f66090b23c Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 2 Sep 2015 14:13:16 -0700 Subject: [PATCH] React to Options, Configure => Add, Cookie changes UseCookie now has an overload which takes an instance of CookieOptions --- samples/SocialSample/Startup.cs | 2 +- .../CookieAppBuilderExtensions.cs | 7 +-- .../CookieAuthenticationOptions.cs | 11 +++- .../CookieServiceCollectionExtensions.cs | 18 ++----- .../FacebookAppBuilderExtensions.cs | 7 +-- .../FacebookServiceCollectionExtensions.cs | 18 ++----- .../GoogleAppBuilderExtensions.cs | 5 +- .../GoogleServiceCollectionExtensions.cs | 18 ++----- .../JwtBearerAppBuilderExtensions.cs | 5 +- .../JwtBearerServiceCollectionExtensions.cs | 14 +----- .../MicrosoftAccountAppBuilderExtensions.cs | 7 +-- ...osoftAccountServiceCollectionExtensions.cs | 18 ++----- .../OAuthAuthenticationExtensions.cs | 5 +- .../OAuthAuthenticationMiddleware.cs | 2 +- .../OpenIdConnectAuthenticationExtensions.cs | 7 +-- .../OpenIdConnectAuthenticationMiddleware.cs | 4 +- ...penIdConnectServiceCollectionExtensions.cs | 18 ++----- .../TwitterAppBuilderExtensions.cs | 7 +-- .../TwitterAuthenticationMiddleware.cs | 2 +- .../TwitterServiceCollectionExtensions.cs | 18 ++----- .../AuthenticationMiddleware.cs | 8 +-- ...thenticationServiceCollectionExtensions.cs | 6 +-- ...laimsTransformationAppBuilderExtensions.cs | 16 +----- .../ClaimsTransformationMiddleware.cs | 8 +-- .../DefaultAuthorizationService.cs | 2 +- .../ServiceCollectionExtensions.cs | 9 +--- .../Cookies/CookieMiddlewareTests.cs | 6 +-- .../Facebook/FacebookMiddlewareTests.cs | 32 ++++++------ .../Google/GoogleMiddlewareTests.cs | 8 +-- .../DefaultAuthorizationServiceTests.cs | 50 +++++++++---------- 30 files changed, 109 insertions(+), 229 deletions(-) diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index cad2f0a707..2721b5807e 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -26,7 +26,7 @@ namespace CookieSample { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); - services.ConfigureClaimsTransformation(p => + services.AddClaimsTransformation(p => { var id = new ClaimsIdentity("xform"); id.AddClaim(new Claim("ClaimsTransformation", "TransformAddedClaim")); diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs index e125ecc162..5a79654253 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs @@ -20,13 +20,10 @@ namespace Microsoft.AspNet.Builder /// Used to configure the options for the middleware /// The name of the options class that controls the middleware behavior, null will use the default options /// The original app parameter - public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } /// diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs index 468d07522b..52a4d82efc 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs @@ -5,13 +5,14 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.AspNet.Http; using Microsoft.Framework.Internal; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Authentication.Cookies { /// /// Contains the options used by the CookiesAuthenticationMiddleware /// - public class CookieAuthenticationOptions : AuthenticationOptions + public class CookieAuthenticationOptions : AuthenticationOptions, IOptions { private string _cookieName; @@ -146,5 +147,13 @@ namespace Microsoft.AspNet.Authentication.Cookies /// to the client. This can be used to mitigate potential problems with very large identities. /// public IAuthenticationSessionStore SessionStore { get; set; } + + CookieAuthenticationOptions IOptions.Value + { + get + { + return this; + } + } } } diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs index c55cb9d5f0..d609f12bde 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class CookieServiceCollectionExtensions { - public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureCookieAuthentication(configure, optionsName: ""); + return services.Configure(configure); } - public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return services.ConfigureCookieAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs index 24e1e0726c..9c825e6715 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs @@ -18,13 +18,10 @@ namespace Microsoft.AspNet.Builder /// /// The passed to the configure method. /// The updated . - public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs index 911dd18b81..3666f9ecf5 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class FacebookServiceCollectionExtensions { - public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureFacebookAuthentication(configure, optionsName: ""); + return services.Configure(configure); } - public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return services.ConfigureFacebookAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs index e00dcffddf..848e83df70 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs @@ -23,10 +23,7 @@ namespace Microsoft.AspNet.Builder public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs index c5f7041e44..6b47398490 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class GoogleServiceCollectionExtensions { - public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureGoogleAuthentication(configure, optionsName: ""); + return services.Configure(configure); } - public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return services.ConfigureGoogleAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs index 4b14d7ab78..6b73167d89 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs @@ -27,10 +27,7 @@ namespace Microsoft.AspNet.Builder public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs index f026908667..db7633bfe2 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs @@ -15,22 +15,12 @@ namespace Microsoft.Framework.DependencyInjection { public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureJwtBearerAuthentication(configure, optionsName: ""); - } - - public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) - { - return services.Configure(configure, optionsName); + return services.Configure(configure); } public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.ConfigureJwtBearerAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.ConfigureJwtBearerAuthentication(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs index b7c1d0ca9a..0bb6dc905e 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs @@ -13,13 +13,10 @@ namespace Microsoft.AspNet.Builder /// public static class MicrosoftAccountAuthenticationExtensions { - public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs index 86b68230d6..fb7d6ce3f1 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class MicrosoftAccountServiceCollectionExtensions { - public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureMicrosoftAccountAuthentication(configure, optionsName: ""); + return services.Configure(configure); } - public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return services.ConfigureMicrosoftAccountAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs index fec82a735e..264cb831f4 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs @@ -30,10 +30,7 @@ namespace Microsoft.AspNet.Builder { configureOptions(options); } - }) - { - Name = authenticationScheme, - }); + })); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs index 55ab6f1ab4..9590573c6a 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Authentication.OAuth if (string.IsNullOrEmpty(Options.SignInScheme)) { - Options.SignInScheme = sharedOptions.Options.SignInScheme; + Options.SignInScheme = sharedOptions.Value.SignInScheme; } } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs index c4a1961f10..001d583abe 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs @@ -18,13 +18,10 @@ namespace Microsoft.AspNet.Builder /// The application builder /// Options which control the processing of the OpenIdConnect protocol and token validation. /// The application builder - public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action configureOptions = null) { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } /// diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs index b26fd1f5e8..fb714fb001 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs @@ -49,9 +49,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect ConfigureOptions configureOptions = null) : base(next, options, loggerFactory, encoder, configureOptions) { - if (string.IsNullOrEmpty(Options.SignInScheme) && !string.IsNullOrEmpty(sharedOptions.Options.SignInScheme)) + if (string.IsNullOrEmpty(Options.SignInScheme) && !string.IsNullOrEmpty(sharedOptions.Value.SignInScheme)) { - Options.SignInScheme = sharedOptions.Options.SignInScheme; + Options.SignInScheme = sharedOptions.Value.SignInScheme; } if (Options.HtmlEncoder == null) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs index 394ebe3f36..029ed08acc 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class OpenIdConnectServiceCollectionExtensions { - public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return ConfigureOpenIdConnectAuthentication(services, configure, null); + return services.Configure(configure); } - public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return ConfigureOpenIdConnectAuthentication(services, config, null); - } - - public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs index 04e36058f0..15267d02ac 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs @@ -13,13 +13,10 @@ namespace Microsoft.AspNet.Builder /// public static class TwitterAppBuilderExtensions { - public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { })) - { - Name = optionsName - }); + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs index 30d4fe3e98..2f197896a0 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Authentication.Twitter if (string.IsNullOrEmpty(Options.SignInScheme)) { - Options.SignInScheme = sharedOptions.Options.SignInScheme; + Options.SignInScheme = sharedOptions.Value.SignInScheme; } if (string.IsNullOrEmpty(Options.SignInScheme)) { diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs index 553bd1ba88..75dc1465fe 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs @@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class TwitterAuthenticationExtensions { - public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { - return services.ConfigureTwitterAuthentication(configure, optionsName: ""); + return services.Configure(configure); } - public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure, string optionsName) + public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(configure, optionsName); - } - - public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) - { - return services.ConfigureTwitterAuthentication(config, optionsName: ""); - } - - public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config, string optionsName) - { - return services.Configure(config, optionsName); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs index 7d83092a40..c0eee7e1a0 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs @@ -23,14 +23,10 @@ namespace Microsoft.AspNet.Authentication [NotNull] IUrlEncoder encoder, ConfigureOptions configureOptions) { + Options = options.Value; if (configureOptions != null) { - Options = options.GetNamedOptions(configureOptions.Name); - configureOptions.Configure(Options, configureOptions.Name); - } - else - { - Options = options.Options; + configureOptions.Configure(Options); } Logger = loggerFactory.CreateLogger(this.GetType().FullName); UrlEncoder = encoder; diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication/AuthenticationServiceCollectionExtensions.cs index a2ccd6c976..9634fd97b7 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationServiceCollectionExtensions.cs @@ -24,17 +24,17 @@ namespace Microsoft.Framework.DependencyInjection return services.AddAuthentication(); } - public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } - public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func transform) + public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func transform) { return services.Configure(o => o.Transformer = new ClaimsTransformer { TransformSyncDelegate = transform }); } - public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func> asyncTransform) + public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func> asyncTransform) { return services.Configure(o => o.Transformer = new ClaimsTransformer { TransformAsyncDelegate = asyncTransform }); } diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs index c18317f830..ff29ffdbe7 100644 --- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAppBuilderExtensions.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Builder /// The original app parameter public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app) { - return app.UseClaimsTransformation(configureOptions: o => { }, optionsName: string.Empty); + return app.UseClaimsTransformation(configureOptions: o => { }); } /// @@ -30,21 +30,9 @@ namespace Microsoft.AspNet.Builder /// Used to configure the options for the middleware /// The original app parameter public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action configureOptions) - { - return app.UseClaimsTransformation(configureOptions: configureOptions, optionsName: string.Empty); - } - - /// - /// Adds a claims transformation middleware to your web application pipeline. - /// - /// The IApplicationBuilder passed to your configuration method - /// Used to configure the options for the middleware - /// The name of the options class that controls the middleware behavior, null will use the default options - /// The original app parameter - public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action configureOptions, [NotNull] string optionsName) { return app.UseMiddleware( - new ConfigureOptions(configureOptions) { Name = optionsName }); + new ConfigureOptions(configureOptions)); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs index eb616d9fb9..9d7af5b448 100644 --- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs @@ -18,14 +18,10 @@ namespace Microsoft.AspNet.Authentication [NotNull] IOptions options, ConfigureOptions configureOptions) { + Options = options.Value; if (configureOptions != null) { - Options = options.GetNamedOptions(configureOptions.Name); - configureOptions.Configure(Options, configureOptions.Name); - } - else - { - Options = options.Options; + configureOptions.Configure(Options); } _next = next; } diff --git a/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs b/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs index 522b9d3231..4095c623e7 100644 --- a/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs +++ b/src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authorization public DefaultAuthorizationService(IOptions options, IEnumerable handlers) { _handlers = handlers.ToArray(); - _options = options.Options; + _options = options.Value; } public async Task AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable requirements) diff --git a/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs index ecad6ff4b8..92f93fe1a3 100644 --- a/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authorization/ServiceCollectionExtensions.cs @@ -10,11 +10,6 @@ namespace Microsoft.Framework.DependencyInjection { public static class ServiceCollectionExtensions { - public static IServiceCollection ConfigureAuthorization([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - public static IServiceCollection AddAuthorization([NotNull] this IServiceCollection services) { services.AddOptions(); @@ -23,9 +18,9 @@ namespace Microsoft.Framework.DependencyInjection return services; } - public static IServiceCollection AddAuthorization([NotNull] this IServiceCollection services, [NotNull] Action configureOptions) + public static IServiceCollection AddAuthorization([NotNull] this IServiceCollection services, [NotNull] Action configure) { - services.ConfigureAuthorization(configureOptions); + services.Configure(configure); return services.AddAuthorization(); } } diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index f438ff5802..139006b06e 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -977,7 +977,7 @@ namespace Microsoft.AspNet.Authentication.Cookies if (claimsTransform != null) { - app.UseClaimsTransformation(); + app.UseClaimsTransformation(claimsTransform); } app.Use(async (context, next) => { @@ -1033,10 +1033,6 @@ namespace Microsoft.AspNet.Authentication.Cookies services => { services.AddAuthentication(); - if (claimsTransform != null) - { - services.ConfigureClaimsTransformation(claimsTransform); - } }); server.BaseAddress = baseAddress; return server; diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index 7ebe9cd3c4..5cd06921a5 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -35,8 +35,11 @@ namespace Microsoft.AspNet.Authentication.Facebook }, services => { - services.AddAuthentication(); - services.ConfigureFacebookAuthentication(options => + services.AddAuthentication(options => + { + options.SignInScheme = "External"; + }); + services.AddFacebookAuthentication(options => { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; @@ -48,15 +51,11 @@ namespace Microsoft.AspNet.Authentication.Facebook } }; }); - services.ConfigureCookieAuthentication(options => + services.AddCookieAuthentication(options => { options.AuthenticationScheme = "External"; options.AutomaticAuthentication = true; }); - services.Configure(options => - { - options.SignInScheme = "External"; - }); }, context => { @@ -81,7 +80,7 @@ namespace Microsoft.AspNet.Authentication.Facebook services => { services.AddAuthentication(); - services.ConfigureFacebookAuthentication(options => + services.AddFacebookAuthentication(options => { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; @@ -112,7 +111,7 @@ namespace Microsoft.AspNet.Authentication.Facebook services => { services.AddAuthentication(); - services.ConfigureFacebookAuthentication(options => + services.AddFacebookAuthentication(options => { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; @@ -142,20 +141,19 @@ namespace Microsoft.AspNet.Authentication.Facebook }, services => { - services.AddAuthentication(); - services.ConfigureFacebookAuthentication(options => + services.AddAuthentication(options => + { + options.SignInScheme = "External"; + }); + services.AddFacebookAuthentication(options => { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; }); - services.ConfigureCookieAuthentication(options => + services.AddCookieAuthentication(options => { options.AuthenticationScheme = "External"; }); - services.Configure(options => - { - options.SignInScheme = "External"; - }); }, context => { @@ -189,7 +187,7 @@ namespace Microsoft.AspNet.Authentication.Facebook services => { services.AddAuthentication(); - services.ConfigureFacebookAuthentication(options => + services.AddFacebookAuthentication(options => { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index f75a97643a..e13b051462 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -600,12 +600,8 @@ namespace Microsoft.AspNet.Authentication.Google }, services => { - services.AddAuthentication(); - services.Configure(options => - { - options.SignInScheme = TestExtensions.CookieAuthenticationScheme; - }); - services.ConfigureClaimsTransformation(p => + services.AddAuthentication(options => options.SignInScheme = TestExtensions.CookieAuthenticationScheme); + services.AddClaimsTransformation(p => { var id = new ClaimsIdentity("xform"); id.AddClaim(new Claim("xform", "yup")); diff --git a/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs b/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs index d67ff91637..41c1c79d62 100644 --- a/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs +++ b/test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); @@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage", "CanViewAnything")); }); @@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -183,7 +183,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -246,7 +246,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireClaim("Permission", "CanViewPage")); }); @@ -407,7 +407,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireRole("Admin", "Users")); }); @@ -431,7 +431,7 @@ namespace Microsoft.AspNet.Authorization.Test { Assert.Throws(() => BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => { }); }); @@ -444,7 +444,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Hao", policy => policy.RequireUserName("Hao")); }); @@ -470,7 +470,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Hao", policy => policy.RequireUserName("Hao")); }); @@ -496,7 +496,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Hao", policy => policy.RequireUserName("Hao")); }); @@ -518,7 +518,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Hao", policy => policy.RequireRole("Hao")); }); @@ -540,7 +540,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Any", policy => policy.RequireAuthenticatedUser()); }); @@ -565,7 +565,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Any", policy => policy.RequireAuthenticatedUser()); }); @@ -594,7 +594,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Custom", policy => policy.Requirements.Add(new CustomRequirement())); }); @@ -615,7 +615,7 @@ namespace Microsoft.AspNet.Authorization.Test var authorizationService = BuildAuthorizationService(services => { services.AddTransient(); - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Custom", policy => policy.Requirements.Add(new CustomRequirement())); }); @@ -654,7 +654,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Passthrough", policy => policy.Requirements.Add(new PassThroughRequirement(shouldSucceed))); }); @@ -674,7 +674,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); @@ -702,7 +702,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); @@ -729,7 +729,7 @@ namespace Microsoft.AspNet.Authorization.Test // Arrange var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { var basePolicy = new AuthorizationPolicyBuilder().RequireClaim("Base", "Value").Build(); options.AddPolicy("Combined", policy => policy.Combine(basePolicy).RequireClaim("Claim", "Exists")); @@ -835,7 +835,7 @@ namespace Microsoft.AspNet.Authorization.Test { var authorizationService = BuildAuthorizationService(services => { - services.ConfigureAuthorization(options => + services.AddAuthorization(options => { options.AddPolicy("Basic", policy => policy.RequireDelegate((context, req) => context.Succeed(req))); });