Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 78f472f

Browse files
committed
Switch to automatically ensure request services
1 parent 45836c8 commit 78f472f

File tree

12 files changed

+33
-17
lines changed

12 files changed

+33
-17
lines changed

samples/CookieSample/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class Startup
99
{
1010
public void Configure(IApplicationBuilder app)
1111
{
12-
app.UseServices(services => { });
1312
app.UseCookieAuthentication(options =>
1413
{
1514
});

samples/CookieSessionSample/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class Startup
1010
{
1111
public void Configure(IApplicationBuilder app)
1212
{
13-
app.UseRequestServices();
1413
app.UseCookieAuthentication(options =>
1514
{
1615
options.SessionStore = new MemoryCacheSessionStore();

src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ public class CookieAuthenticationMiddleware : AuthenticationMiddleware<CookieAut
1818
private readonly ILogger _logger;
1919

2020
public CookieAuthenticationMiddleware(RequestDelegate next,
21+
IServiceProvider services,
2122
IDataProtectionProvider dataProtectionProvider,
2223
ILoggerFactory loggerFactory,
2324
IOptions<CookieAuthenticationOptions> options,
2425
ConfigureOptions<CookieAuthenticationOptions> configureOptions)
25-
: base(next, options, configureOptions)
26+
: base(next, services, options, configureOptions)
2627
{
2728
if (Options.Notifications == null)
2829
{

src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ public class FacebookAuthenticationMiddleware : OAuthAuthenticationMiddleware<Fa
2626
/// <param name="options">Configuration options for the middleware.</param>
2727
public FacebookAuthenticationMiddleware(
2828
RequestDelegate next,
29+
IServiceProvider services,
2930
IDataProtectionProvider dataProtectionProvider,
3031
ILoggerFactory loggerFactory,
3132
IOptions<ExternalAuthenticationOptions> externalOptions,
3233
IOptions<FacebookAuthenticationOptions> options,
3334
ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
34-
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
35+
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
3536
{
3637
if (string.IsNullOrWhiteSpace(Options.AppId))
3738
{

src/Microsoft.AspNet.Security.Google/GoogleAuthenticationMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ public class GoogleAuthenticationMiddleware : OAuthAuthenticationMiddleware<Goog
2525
/// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>.
2626
/// </summary>
2727
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
28+
/// <param name="services"></param>
2829
/// <param name="dataProtectionProvider"></param>
2930
/// <param name="loggerFactory"></param>
3031
/// <param name="options">Configuration options for the middleware.</param>
3132
public GoogleAuthenticationMiddleware(
3233
RequestDelegate next,
34+
IServiceProvider services,
3335
IDataProtectionProvider dataProtectionProvider,
3436
ILoggerFactory loggerFactory,
3537
IOptions<ExternalAuthenticationOptions> externalOptions,
3638
IOptions<GoogleAuthenticationOptions> options,
3739
ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
38-
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
40+
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
3941
{
4042
if (Options.Notifications == null)
4143
{

src/Microsoft.AspNet.Security.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ public class MicrosoftAccountAuthenticationMiddleware : OAuthAuthenticationMiddl
2121
/// Initializes a new <see cref="MicrosoftAccountAuthenticationMiddleware"/>.
2222
/// </summary>
2323
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
24+
/// <param name="services"></param>
2425
/// <param name="dataProtectionProvider"></param>
2526
/// <param name="loggerFactory"></param>
2627
/// <param name="options">Configuration options for the middleware.</param>
2728
public MicrosoftAccountAuthenticationMiddleware(
2829
RequestDelegate next,
30+
IServiceProvider services,
2931
IDataProtectionProvider dataProtectionProvider,
3032
ILoggerFactory loggerFactory,
3133
IOptions<ExternalAuthenticationOptions> externalOptions,
3234
IOptions<MicrosoftAccountAuthenticationOptions> options,
3335
ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
34-
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
36+
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
3537
{
3638
if (Options.Notifications == null)
3739
{

src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ public class OAuthAuthenticationMiddleware<TOptions, TNotifications> : Authentic
2626
/// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>.
2727
/// </summary>
2828
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
29+
/// <param name="services"></param>
2930
/// <param name="dataProtectionProvider"></param>
3031
/// <param name="loggerFactory"></param>
3132
/// <param name="options">Configuration options for the middleware.</param>
3233
public OAuthAuthenticationMiddleware(
3334
RequestDelegate next,
35+
IServiceProvider services,
3436
IDataProtectionProvider dataProtectionProvider,
3537
ILoggerFactory loggerFactory,
3638
IOptions<ExternalAuthenticationOptions> externalOptions,
3739
IOptions<TOptions> options,
3840
ConfigureOptions<TOptions> configureOptions = null)
39-
: base(next, options, configureOptions)
41+
: base(next, services, options, configureOptions)
4042
{
4143
// todo: review error handling
4244
if (string.IsNullOrWhiteSpace(Options.AuthenticationType))

src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNet.Security.Infrastructure;
88
using Microsoft.Framework.Logging;
99
using Microsoft.Framework.OptionsModel;
10+
using System;
1011

1112
namespace Microsoft.AspNet.Security.OAuth
1213
{
@@ -28,11 +29,12 @@ public class OAuthBearerAuthenticationMiddleware : AuthenticationMiddleware<OAut
2829
/// </summary>
2930
public OAuthBearerAuthenticationMiddleware(
3031
RequestDelegate next,
32+
IServiceProvider services,
3133
IDataProtectionProvider dataProtectionProvider,
3234
ILoggerFactory loggerFactory,
3335
IOptions<OAuthBearerAuthenticationOptions> options,
3436
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
35-
: base(next, options, configureOptions)
37+
: base(next, services, options, configureOptions)
3638
{
3739
_logger = loggerFactory.Create<OAuthBearerAuthenticationMiddleware>();
3840

src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ public class TwitterAuthenticationMiddleware : AuthenticationMiddleware<TwitterA
2929
/// Initializes a <see cref="TwitterAuthenticationMiddleware"/>
3030
/// </summary>
3131
/// <param name="next">The next middleware in the HTTP pipeline to invoke</param>
32+
/// <param name="services"></param>
3233
/// <param name="dataProtectionProvider"></param>
3334
/// <param name="loggerFactory"></param>
3435
/// <param name="options">Configuration options for the middleware</param>
3536
public TwitterAuthenticationMiddleware(
3637
RequestDelegate next,
38+
IServiceProvider services,
3739
IDataProtectionProvider dataProtectionProvider,
3840
ILoggerFactory loggerFactory,
3941
IOptions<ExternalAuthenticationOptions> externalOptions,
4042
IOptions<TwitterAuthenticationOptions> options,
4143
ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
42-
: base(next, options, configureOptions)
44+
: base(next, services, options, configureOptions)
4345
{
4446
if (string.IsNullOrWhiteSpace(Options.ConsumerSecret))
4547
{

src/Microsoft.AspNet.Security/Infrastructure/AuthenticationMiddleware.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
using System.Threading.Tasks;
77
using Microsoft.AspNet.Builder;
88
using Microsoft.AspNet.Http;
9+
using Microsoft.AspNet.RequestContainer;
910
using Microsoft.Framework.OptionsModel;
1011

1112
namespace Microsoft.AspNet.Security.Infrastructure
1213
{
1314
public abstract class AuthenticationMiddleware<TOptions> where TOptions : AuthenticationOptions, new()
1415
{
1516
private readonly RequestDelegate _next;
17+
private readonly IServiceProvider _services;
1618

17-
protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IOptions<TOptions> options, ConfigureOptions<TOptions> configureOptions)
19+
protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IServiceProvider services, [NotNull] IOptions<TOptions> options, ConfigureOptions<TOptions> configureOptions)
1820
{
1921
if (configureOptions != null)
2022
{
@@ -26,6 +28,7 @@ protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IOp
2628
Options = options.Options;
2729
}
2830
_next = next;
31+
_services = services;
2932
}
3033

3134
public string AuthenticationType { get; set; }
@@ -34,15 +37,18 @@ protected AuthenticationMiddleware([NotNull] RequestDelegate next, [NotNull] IOp
3437

3538
public async Task Invoke(HttpContext context)
3639
{
37-
AuthenticationHandler<TOptions> handler = CreateHandler();
38-
await handler.Initialize(Options, context);
39-
if (!await handler.InvokeAsync())
40+
using (RequestServicesContainer.EnsureRequestServices(context, _services))
4041
{
41-
await _next(context);
42+
AuthenticationHandler<TOptions> handler = CreateHandler();
43+
await handler.Initialize(Options, context);
44+
if (!await handler.InvokeAsync())
45+
{
46+
await _next(context);
47+
}
48+
await handler.TeardownAsync();
4249
}
43-
await handler.TeardownAsync();
4450
}
4551

4652
protected abstract AuthenticationHandler<TOptions> CreateHandler();
4753
}
48-
}
54+
}

0 commit comments

Comments
 (0)