From 776593ec712931140d325808dae89668e91ac258 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 19 Mar 2015 11:04:33 -0700 Subject: [PATCH] React to hosting changes --- samples/CookieSample/Startup.cs | 10 +-- samples/CookieSessionSample/Startup.cs | 10 +-- samples/OpenIdConnectSample/Startup.cs | 19 ++-- .../CookieAuthenticationMiddleware.cs | 3 +- .../FacebookAuthenticationMiddleware.cs | 3 +- .../FacebookAuthenticatedContext.cs | 1 - .../project.json | 3 +- .../GoogleAuthenticationMiddleware.cs | 4 +- ...icrosoftAccountAuthenticationMiddleware.cs | 4 +- .../OAuthAuthenticationHandler.cs | 4 +- .../OAuthAuthenticationMiddleware.cs | 4 +- .../project.json | 3 +- .../OAuthBearerAuthenticationMiddleware.cs | 3 +- .../OpenIdConnectAuthenticationMiddleware.cs | 3 +- .../TwitterAuthenticationMiddleware.cs | 3 +- .../AuthenticationMiddleware.cs | 37 ++++---- .../project.json | 2 +- .../Cookies/CookieMiddlewareTests.cs | 19 ++-- .../Facebook/FacebookMiddlewareTests.cs | 89 ++++++++++--------- .../Google/GoogleMiddlewareTests.cs | 30 +++---- .../MicrosoftAccountMiddlewareTests.cs | 16 ++-- .../OAuthBearer/OAuthBearerMiddlewareTests.cs | 8 +- .../OpenIdConnectMiddlewareTests.cs | 19 ++-- .../Twitter/TwitterMiddlewareTests.cs | 16 ++-- 24 files changed, 143 insertions(+), 170 deletions(-) diff --git a/samples/CookieSample/Startup.cs b/samples/CookieSample/Startup.cs index d5b0814fa2..d7c3e31282 100644 --- a/samples/CookieSample/Startup.cs +++ b/samples/CookieSample/Startup.cs @@ -8,13 +8,13 @@ namespace CookieSample { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + services.AddDataProtection(); + } + public void Configure(IApplicationBuilder app) { - app.UseServices(services => - { - services.AddDataProtection(); - }); - app.UseCookieAuthentication(options => { }); diff --git a/samples/CookieSessionSample/Startup.cs b/samples/CookieSessionSample/Startup.cs index dacb7956fc..f93777758a 100644 --- a/samples/CookieSessionSample/Startup.cs +++ b/samples/CookieSessionSample/Startup.cs @@ -9,13 +9,13 @@ namespace CookieSessionSample { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + services.AddDataProtection(); + } + public void Configure(IApplicationBuilder app) { - app.UseServices(services => - { - services.AddDataProtection(); - }); - app.UseCookieAuthentication(options => { options.SessionStore = new MemoryCacheSessionStore(); diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index 40e0f5a77a..cb748b5d6d 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -10,18 +10,17 @@ namespace OpenIdConnectSample { public class Startup { + public void ConfigureServices(IServiceCollection services) + { + services.AddDataProtection(); + services.Configure(options => + { + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; + }); + } + public void Configure(IApplicationBuilder app) { - app.UseServices(services => - { - services.AddDataProtection(); - services.Configure(options => - { - options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }); - - }); - app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs index 2082f23659..0b4afe1257 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs @@ -18,12 +18,11 @@ namespace Microsoft.AspNet.Authentication.Cookies public CookieAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions options, ConfigureOptions configureOptions) - : base(next, services, options, configureOptions) + : base(next, options, configureOptions) { if (Options.Notifications == null) { diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs index d15b8d1020..7feacb1d12 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs @@ -26,13 +26,12 @@ namespace Microsoft.AspNet.Authentication.Facebook /// Configuration options for the middleware. public FacebookAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions = null) - : base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) + : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) { if (string.IsNullOrWhiteSpace(Options.AppId)) { diff --git a/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs index b64f6dd38e..084b273479 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/Notifications/FacebookAuthenticatedContext.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Net.Http; using Microsoft.AspNet.Http; using Microsoft.AspNet.Authentication.OAuth; using Newtonsoft.Json.Linq; diff --git a/src/Microsoft.AspNet.Authentication.Facebook/project.json b/src/Microsoft.AspNet.Authentication.Facebook/project.json index 0dab9e868a..7bce6f458e 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/project.json +++ b/src/Microsoft.AspNet.Authentication.Facebook/project.json @@ -3,7 +3,8 @@ "description": "ASP.NET 5 middleware that enables an application to support Facebook's OAuth 2.0 authentication workflow.", "dependencies": { "Microsoft.AspNet.Authentication.OAuth": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, + "Newtonsoft.Json": "6.0.6" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs index 4641bcd0ea..73e6b180b5 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs @@ -22,19 +22,17 @@ namespace Microsoft.AspNet.Authentication.Google /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. - /// /// /// /// Configuration options for the middleware. public GoogleAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions = null) - : base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) + : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) { if (Options.Notifications == null) { diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs index 66cdde6bd3..7626c70619 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs @@ -20,19 +20,17 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. - /// /// /// /// Configuration options for the middleware. public MicrosoftAccountAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions = null) - : base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) + : base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) { if (Options.Notifications == null) { diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs index b8696a302b..6389b8c1d5 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs @@ -5,12 +5,10 @@ using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; -using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Extensions; using Microsoft.AspNet.Http.Authentication; -using Microsoft.AspNet.Authentication; +using Microsoft.AspNet.Http.Extensions; using Microsoft.AspNet.WebUtilities; using Microsoft.Framework.Logging; using Newtonsoft.Json.Linq; diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs index ef43d309ba..8b8e432b34 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs @@ -26,19 +26,17 @@ namespace Microsoft.AspNet.Authentication.OAuth /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. - /// /// /// /// Configuration options for the middleware. public OAuthAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions = null) - : base(next, services, options, configureOptions) + : base(next, options, configureOptions) { // todo: review error handling if (string.IsNullOrWhiteSpace(Options.AuthenticationScheme)) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/project.json b/src/Microsoft.AspNet.Authentication.OAuth/project.json index ab9059a181..215b5155d0 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/project.json +++ b/src/Microsoft.AspNet.Authentication.OAuth/project.json @@ -4,7 +4,8 @@ "dependencies": { "Microsoft.AspNet.DataProtection": "1.0.0-*", "Microsoft.AspNet.Authentication": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, + "Newtonsoft.Json": "6.0.6" }, "frameworks": { "dnx451": { diff --git a/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs index debaf1e689..9ab829c5d2 100644 --- a/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationMiddleware.cs @@ -31,11 +31,10 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer /// public OAuthBearerAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions options, ConfigureOptions configureOptions) - : base(next, services, options, configureOptions) + : base(next, options, configureOptions) { _logger = loggerFactory.CreateLogger(); if (Options.Notifications == null) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs index 0659a086ed..53284a50e9 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs @@ -36,13 +36,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")] public OpenIdConnectAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions) - : base(next, services, options, configureOptions) + : base(next, options, configureOptions) { _logger = loggerFactory.CreateLogger(); diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs index 5e07f7eea7..63534a85f5 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs @@ -35,13 +35,12 @@ namespace Microsoft.AspNet.Authentication.Twitter /// Configuration options for the middleware public TwitterAuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IOptions externalOptions, [NotNull] IOptions options, ConfigureOptions configureOptions = null) - : base(next, services, options, configureOptions) + : base(next, options, configureOptions) { if (string.IsNullOrWhiteSpace(Options.ConsumerSecret)) { diff --git a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs index a9482ed465..b9eaa36f83 100644 --- a/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.RequestContainer; using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; @@ -14,11 +13,9 @@ namespace Microsoft.AspNet.Authentication public abstract class AuthenticationMiddleware where TOptions : AuthenticationOptions, new() { private readonly RequestDelegate _next; - private readonly IServiceProvider _services; protected AuthenticationMiddleware( [NotNull] RequestDelegate next, - [NotNull] IServiceProvider services, [NotNull] IOptions options, ConfigureOptions configureOptions) { @@ -32,7 +29,6 @@ namespace Microsoft.AspNet.Authentication Options = options.Options; } _next = next; - _services = services; } public string AuthenticationScheme { get; set; } @@ -41,32 +37,29 @@ namespace Microsoft.AspNet.Authentication public async Task Invoke(HttpContext context) { - using (RequestServicesContainer.EnsureRequestServices(context, _services)) + AuthenticationHandler handler = CreateHandler(); + await handler.Initialize(Options, context); + try + { + if (!await handler.InvokeAsync()) + { + await _next(context); + } + } + catch (Exception) { - AuthenticationHandler handler = CreateHandler(); - await handler.Initialize(Options, context); try { - if (!await handler.InvokeAsync()) - { - await _next(context); - } + handler.Faulted = true; + await handler.TeardownAsync(); } catch (Exception) { - try - { - handler.Faulted = true; - await handler.TeardownAsync(); - } - catch (Exception) - { - // Don't mask the original exception - } - throw; + // Don't mask the original exception } - await handler.TeardownAsync(); + throw; } + await handler.TeardownAsync(); } protected abstract AuthenticationHandler CreateHandler(); diff --git a/src/Microsoft.AspNet.Authentication/project.json b/src/Microsoft.AspNet.Authentication/project.json index 81b89148df..83840f36cb 100644 --- a/src/Microsoft.AspNet.Authentication/project.json +++ b/src/Microsoft.AspNet.Authentication/project.json @@ -3,9 +3,9 @@ "description": "ASP.NET 5 common types used by the various authentication middleware.", "dependencies": { "Microsoft.AspNet.DataProtection": "1.0.0-*", - "Microsoft.AspNet.RequestContainer": "1.0.0-*", "Microsoft.AspNet.Http.Interfaces": "1.0.0-*", "Microsoft.AspNet.Http.Core": "1.0.0-*", + "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.Logging.Interfaces": "1.0.0-*", "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index ea38856504..0a0e5a8da3 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -524,17 +524,6 @@ namespace Microsoft.AspNet.Authentication.Cookies { var server = TestServer.Create(app => { - if (claimsTransform != null) - { - app.UseServices(services => { - services.AddDataProtection(); - services.ConfigureClaimsTransformation(claimsTransform); - }); - } - else - { - app.UseServices(services => services.AddDataProtection()); - } app.UseCookieAuthentication(configureOptions); if (claimsTransform != null) { @@ -581,6 +570,14 @@ namespace Microsoft.AspNet.Authentication.Cookies await next(); } }); + }, + services => + { + services.AddDataProtection(); + 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 ba00fb1253..fd349582fb 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -24,34 +24,34 @@ namespace Microsoft.AspNet.Authentication.Facebook var server = CreateServer( app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.ConfigureFacebookAuthentication(options => - { - options.AppId = "Test App Id"; - options.AppSecret = "Test App Secret"; - options.Notifications = new FacebookAuthenticationNotifications - { - OnApplyRedirect = context => - { - context.Response.Redirect(context.RedirectUri + "&custom=test"); - } - }; - }); - services.ConfigureCookieAuthentication(options => - { - options.AuthenticationScheme = "External"; - options.AutomaticAuthentication = true; - }); - services.Configure(options => - { - options.SignInScheme = "External"; - }); - }); app.UseFacebookAuthentication(); app.UseCookieAuthentication(); }, + services => + { + services.AddDataProtection(); + services.ConfigureFacebookAuthentication(options => + { + options.AppId = "Test App Id"; + options.AppSecret = "Test App Secret"; + options.Notifications = new FacebookAuthenticationNotifications + { + OnApplyRedirect = context => + { + context.Response.Redirect(context.RedirectUri + "&custom=test"); + } + }; + }); + services.ConfigureCookieAuthentication(options => + { + options.AuthenticationScheme = "External"; + options.AutomaticAuthentication = true; + }); + services.Configure(options => + { + options.SignInScheme = "External"; + }); + }, context => { context.Response.Challenge("Facebook"); @@ -69,26 +69,26 @@ namespace Microsoft.AspNet.Authentication.Facebook var server = CreateServer( app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.ConfigureFacebookAuthentication(options => - { - options.AppId = "Test App Id"; - options.AppSecret = "Test App Secret"; - }); - services.ConfigureCookieAuthentication(options => - { - options.AuthenticationScheme = "External"; - }); - services.Configure(options => - { - options.SignInScheme = "External"; - }); - }); app.UseFacebookAuthentication(); app.UseCookieAuthentication(); }, + services => + { + services.AddDataProtection(); + services.ConfigureFacebookAuthentication(options => + { + options.AppId = "Test App Id"; + options.AppSecret = "Test App Secret"; + }); + services.ConfigureCookieAuthentication(options => + { + options.AuthenticationScheme = "External"; + }); + services.Configure(options => + { + options.SignInScheme = "External"; + }); + }, context => { context.Response.Challenge("Facebook"); @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Authentication.Facebook location.ShouldContain("state="); } - private static TestServer CreateServer(Action configure, Func handler) + private static TestServer CreateServer(Action configure, Action configureServices, Func handler) { return TestServer.Create(app => { @@ -120,7 +120,8 @@ namespace Microsoft.AspNet.Authentication.Facebook await next(); } }); - }); + }, + configureServices); } private static async Task SendAsync(TestServer server, string uri, string cookieHeader = null) diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index c870220113..33612b7efc 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -482,21 +482,6 @@ namespace Microsoft.AspNet.Authentication.Google { return TestServer.Create(app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.Configure(options => - { - options.SignInScheme = CookieAuthenticationScheme; - }); - services.ConfigureClaimsTransformation(p => - { - var id = new ClaimsIdentity("xform"); - id.AddClaim(new Claim("xform", "yup")); - p.AddIdentity(id); - return p; - }); - }); app.UseCookieAuthentication(options => { options.AuthenticationScheme = CookieAuthenticationScheme; @@ -542,6 +527,21 @@ namespace Microsoft.AspNet.Authentication.Google await next(); } }); + }, + services => + { + services.AddDataProtection(); + services.Configure(options => + { + options.SignInScheme = CookieAuthenticationScheme; + }); + services.ConfigureClaimsTransformation(p => + { + var id = new ClaimsIdentity("xform"); + id.AddClaim(new Claim("xform", "yup")); + p.AddIdentity(id); + return p; + }); }); } diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index 48372859df..0f22e3ac74 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -161,14 +161,6 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount { return TestServer.Create(app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.Configure(options => - { - options.SignInScheme = "External"; - }); - }); app.UseCookieAuthentication(options => { options.AuthenticationScheme = "External"; @@ -182,6 +174,14 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount await next(); } }); + }, + services => + { + services.AddDataProtection(); + services.Configure(options => + { + options.SignInScheme = "External"; + }); }); } diff --git a/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs index ffbc1a0a4b..fcd2d411ec 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OAuthBearer/OAuthBearerMiddlewareTests.cs @@ -233,11 +233,6 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer { return TestServer.Create(app => { - app.UseServices(services => - { - services.AddDataProtection(); - }); - if (configureOptions != null) { app.UseOAuthBearerAuthentication(configureOptions); @@ -261,7 +256,8 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer } }); - }); + }, + services => services.AddDataProtection()); } private static async Task SendAsync(TestServer server, string uri, string authorizationHeader = null) diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 7681d54668..bec9f1bf3d 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -193,15 +193,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { return TestServer.Create(app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.Configure(options => - { - options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }); - }); - app.UseCookieAuthentication(options => { options.AuthenticationScheme = "OpenIdConnect"; @@ -228,7 +219,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect else if (req.Path == new PathString("/signout_with_specific_redirect_uri")) { res.SignOut( - OpenIdConnectAuthenticationDefaults.AuthenticationScheme, + OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" }); } else if (handler != null) @@ -240,6 +231,14 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect await next(); } }); + }, + services => + { + services.AddDataProtection(); + services.Configure(options => + { + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; + }); }); } diff --git a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index fd281086fc..75220f9214 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -105,14 +105,6 @@ namespace Microsoft.AspNet.Authentication.Twitter { return TestServer.Create(app => { - app.UseServices(services => - { - services.AddDataProtection(); - services.Configure(options => - { - options.SignInScheme = "External"; - }); - }); app.UseCookieAuthentication(options => { options.AuthenticationScheme = "External"; @@ -128,6 +120,14 @@ namespace Microsoft.AspNet.Authentication.Twitter await next(); } }); + }, + services => + { + services.AddDataProtection(); + services.Configure(options => + { + options.SignInScheme = "External"; + }); }); }