React to hosting changes
This commit is contained in:
parent
6086bb0a62
commit
776593ec71
|
|
@ -8,13 +8,13 @@ namespace CookieSample
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app)
|
public void Configure(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ namespace CookieSessionSample
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app)
|
public void Configure(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.SessionStore = new MemoryCacheSessionStore();
|
options.SessionStore = new MemoryCacheSessionStore();
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,17 @@ namespace OpenIdConnectSample
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app)
|
public void Configure(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.Configure<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,11 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
|
|
||||||
public CookieAuthenticationMiddleware(
|
public CookieAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<CookieAuthenticationOptions> options,
|
[NotNull] IOptions<CookieAuthenticationOptions> options,
|
||||||
ConfigureOptions<CookieAuthenticationOptions> configureOptions)
|
ConfigureOptions<CookieAuthenticationOptions> configureOptions)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, options, configureOptions)
|
||||||
{
|
{
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,12 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
/// <param name="options">Configuration options for the middleware.</param>
|
/// <param name="options">Configuration options for the middleware.</param>
|
||||||
public FacebookAuthenticationMiddleware(
|
public FacebookAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<FacebookAuthenticationOptions> options,
|
[NotNull] IOptions<FacebookAuthenticationOptions> options,
|
||||||
ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
|
ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
|
||||||
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Options.AppId))
|
if (string.IsNullOrWhiteSpace(Options.AppId))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// 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.
|
// 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.Http;
|
||||||
using Microsoft.AspNet.Authentication.OAuth;
|
using Microsoft.AspNet.Authentication.OAuth;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
"description": "ASP.NET 5 middleware that enables an application to support Facebook's OAuth 2.0 authentication workflow.",
|
"description": "ASP.NET 5 middleware that enables an application to support Facebook's OAuth 2.0 authentication workflow.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Authentication.OAuth": "1.0.0-*",
|
"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": {
|
"frameworks": {
|
||||||
"dnx451": { },
|
"dnx451": { },
|
||||||
|
|
|
||||||
|
|
@ -22,19 +22,17 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
/// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>.
|
/// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>.
|
||||||
/// </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="options">Configuration options for the middleware.</param>
|
/// <param name="options">Configuration options for the middleware.</param>
|
||||||
public GoogleAuthenticationMiddleware(
|
public GoogleAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<GoogleAuthenticationOptions> options,
|
[NotNull] IOptions<GoogleAuthenticationOptions> options,
|
||||||
ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
|
ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
|
||||||
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
||||||
{
|
{
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,19 +20,17 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||||
/// Initializes a new <see cref="MicrosoftAccountAuthenticationMiddleware"/>.
|
/// Initializes a new <see cref="MicrosoftAccountAuthenticationMiddleware"/>.
|
||||||
/// </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="options">Configuration options for the middleware.</param>
|
/// <param name="options">Configuration options for the middleware.</param>
|
||||||
public MicrosoftAccountAuthenticationMiddleware(
|
public MicrosoftAccountAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<MicrosoftAccountAuthenticationOptions> options,
|
[NotNull] IOptions<MicrosoftAccountAuthenticationOptions> options,
|
||||||
ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
|
ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
|
||||||
: base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
: base(next, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions)
|
||||||
{
|
{
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,10 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Extensions;
|
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
using Microsoft.AspNet.Http.Authentication;
|
||||||
using Microsoft.AspNet.Authentication;
|
using Microsoft.AspNet.Http.Extensions;
|
||||||
using Microsoft.AspNet.WebUtilities;
|
using Microsoft.AspNet.WebUtilities;
|
||||||
using Microsoft.Framework.Logging;
|
using Microsoft.Framework.Logging;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,17 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
/// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>.
|
/// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>.
|
||||||
/// </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="options">Configuration options for the middleware.</param>
|
/// <param name="options">Configuration options for the middleware.</param>
|
||||||
public OAuthAuthenticationMiddleware(
|
public OAuthAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<TOptions> options,
|
[NotNull] IOptions<TOptions> options,
|
||||||
ConfigureOptions<TOptions> configureOptions = null)
|
ConfigureOptions<TOptions> configureOptions = null)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, options, configureOptions)
|
||||||
{
|
{
|
||||||
// todo: review error handling
|
// todo: review error handling
|
||||||
if (string.IsNullOrWhiteSpace(Options.AuthenticationScheme))
|
if (string.IsNullOrWhiteSpace(Options.AuthenticationScheme))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authentication": "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": {
|
"frameworks": {
|
||||||
"dnx451": {
|
"dnx451": {
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,10 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OAuthBearerAuthenticationMiddleware(
|
public OAuthBearerAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<OAuthBearerAuthenticationOptions> options,
|
[NotNull] IOptions<OAuthBearerAuthenticationOptions> options,
|
||||||
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
|
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, options, configureOptions)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger<OAuthBearerAuthenticationMiddleware>();
|
_logger = loggerFactory.CreateLogger<OAuthBearerAuthenticationMiddleware>();
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
[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")]
|
||||||
public OpenIdConnectAuthenticationMiddleware(
|
public OpenIdConnectAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<OpenIdConnectAuthenticationOptions> options,
|
[NotNull] IOptions<OpenIdConnectAuthenticationOptions> options,
|
||||||
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions)
|
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, options, configureOptions)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger<OpenIdConnectAuthenticationMiddleware>();
|
_logger = loggerFactory.CreateLogger<OpenIdConnectAuthenticationMiddleware>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,12 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
/// <param name="options">Configuration options for the middleware</param>
|
/// <param name="options">Configuration options for the middleware</param>
|
||||||
public TwitterAuthenticationMiddleware(
|
public TwitterAuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||||
[NotNull] ILoggerFactory loggerFactory,
|
[NotNull] ILoggerFactory loggerFactory,
|
||||||
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
[NotNull] IOptions<ExternalAuthenticationOptions> externalOptions,
|
||||||
[NotNull] IOptions<TwitterAuthenticationOptions> options,
|
[NotNull] IOptions<TwitterAuthenticationOptions> options,
|
||||||
ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
|
ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, options, configureOptions)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Options.ConsumerSecret))
|
if (string.IsNullOrWhiteSpace(Options.ConsumerSecret))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.RequestContainer;
|
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
using Microsoft.Framework.OptionsModel;
|
using Microsoft.Framework.OptionsModel;
|
||||||
|
|
||||||
|
|
@ -14,11 +13,9 @@ namespace Microsoft.AspNet.Authentication
|
||||||
public abstract class AuthenticationMiddleware<TOptions> where TOptions : AuthenticationOptions, new()
|
public abstract class AuthenticationMiddleware<TOptions> where TOptions : AuthenticationOptions, new()
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly IServiceProvider _services;
|
|
||||||
|
|
||||||
protected AuthenticationMiddleware(
|
protected AuthenticationMiddleware(
|
||||||
[NotNull] RequestDelegate next,
|
[NotNull] RequestDelegate next,
|
||||||
[NotNull] IServiceProvider services,
|
|
||||||
[NotNull] IOptions<TOptions> options,
|
[NotNull] IOptions<TOptions> options,
|
||||||
ConfigureOptions<TOptions> configureOptions)
|
ConfigureOptions<TOptions> configureOptions)
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +29,6 @@ namespace Microsoft.AspNet.Authentication
|
||||||
Options = options.Options;
|
Options = options.Options;
|
||||||
}
|
}
|
||||||
_next = next;
|
_next = next;
|
||||||
_services = services;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AuthenticationScheme { get; set; }
|
public string AuthenticationScheme { get; set; }
|
||||||
|
|
@ -41,32 +37,29 @@ namespace Microsoft.AspNet.Authentication
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
using (RequestServicesContainer.EnsureRequestServices(context, _services))
|
AuthenticationHandler<TOptions> handler = CreateHandler();
|
||||||
|
await handler.Initialize(Options, context);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!await handler.InvokeAsync())
|
||||||
|
{
|
||||||
|
await _next(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
{
|
{
|
||||||
AuthenticationHandler<TOptions> handler = CreateHandler();
|
|
||||||
await handler.Initialize(Options, context);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!await handler.InvokeAsync())
|
handler.Faulted = true;
|
||||||
{
|
await handler.TeardownAsync();
|
||||||
await _next(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
try
|
// Don't mask the original exception
|
||||||
{
|
|
||||||
handler.Faulted = true;
|
|
||||||
await handler.TeardownAsync();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// Don't mask the original exception
|
|
||||||
}
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
await handler.TeardownAsync();
|
throw;
|
||||||
}
|
}
|
||||||
|
await handler.TeardownAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AuthenticationHandler<TOptions> CreateHandler();
|
protected abstract AuthenticationHandler<TOptions> CreateHandler();
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
"description": "ASP.NET 5 common types used by the various authentication middleware.",
|
"description": "ASP.NET 5 common types used by the various authentication middleware.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||||
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
|
|
||||||
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
|
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Http.Core": "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.Logging.Interfaces": "1.0.0-*",
|
||||||
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
|
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -524,17 +524,6 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
var server = TestServer.Create(app =>
|
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);
|
app.UseCookieAuthentication(configureOptions);
|
||||||
if (claimsTransform != null)
|
if (claimsTransform != null)
|
||||||
{
|
{
|
||||||
|
|
@ -581,6 +570,14 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
services =>
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
if (claimsTransform != null)
|
||||||
|
{
|
||||||
|
services.ConfigureClaimsTransformation(claimsTransform);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
server.BaseAddress = baseAddress;
|
server.BaseAddress = baseAddress;
|
||||||
return server;
|
return server;
|
||||||
|
|
|
||||||
|
|
@ -24,34 +24,34 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
var server = CreateServer(
|
var server = CreateServer(
|
||||||
app =>
|
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<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = "External";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
app.UseFacebookAuthentication();
|
app.UseFacebookAuthentication();
|
||||||
app.UseCookieAuthentication();
|
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<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = "External";
|
||||||
|
});
|
||||||
|
},
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
context.Response.Challenge("Facebook");
|
context.Response.Challenge("Facebook");
|
||||||
|
|
@ -69,26 +69,26 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
var server = CreateServer(
|
var server = CreateServer(
|
||||||
app =>
|
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<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = "External";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
app.UseFacebookAuthentication();
|
app.UseFacebookAuthentication();
|
||||||
app.UseCookieAuthentication();
|
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<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = "External";
|
||||||
|
});
|
||||||
|
},
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
context.Response.Challenge("Facebook");
|
context.Response.Challenge("Facebook");
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
location.ShouldContain("state=");
|
location.ShouldContain("state=");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TestServer CreateServer(Action<IApplicationBuilder> configure, Func<HttpContext, bool> handler)
|
private static TestServer CreateServer(Action<IApplicationBuilder> configure, Action<IServiceCollection> configureServices, Func<HttpContext, bool> handler)
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
|
|
@ -120,7 +120,8 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
configureServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null)
|
private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null)
|
||||||
|
|
|
||||||
|
|
@ -482,21 +482,6 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.Configure<ExternalAuthenticationOptions>(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 =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.AuthenticationScheme = CookieAuthenticationScheme;
|
options.AuthenticationScheme = CookieAuthenticationScheme;
|
||||||
|
|
@ -542,6 +527,21 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
services =>
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = CookieAuthenticationScheme;
|
||||||
|
});
|
||||||
|
services.ConfigureClaimsTransformation(p =>
|
||||||
|
{
|
||||||
|
var id = new ClaimsIdentity("xform");
|
||||||
|
id.AddClaim(new Claim("xform", "yup"));
|
||||||
|
p.AddIdentity(id);
|
||||||
|
return p;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,14 +161,6 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.Configure<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = "External";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.AuthenticationScheme = "External";
|
options.AuthenticationScheme = "External";
|
||||||
|
|
@ -182,6 +174,14 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
services =>
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = "External";
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -233,11 +233,6 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (configureOptions != null)
|
if (configureOptions != null)
|
||||||
{
|
{
|
||||||
app.UseOAuthBearerAuthentication(configureOptions);
|
app.UseOAuthBearerAuthentication(configureOptions);
|
||||||
|
|
@ -261,7 +256,8 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
services => services.AddDataProtection());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<Transaction> SendAsync(TestServer server, string uri, string authorizationHeader = null)
|
private static async Task<Transaction> SendAsync(TestServer server, string uri, string authorizationHeader = null)
|
||||||
|
|
|
||||||
|
|
@ -193,15 +193,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.Configure<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.AuthenticationScheme = "OpenIdConnect";
|
options.AuthenticationScheme = "OpenIdConnect";
|
||||||
|
|
@ -228,7 +219,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
else if (req.Path == new PathString("/signout_with_specific_redirect_uri"))
|
else if (req.Path == new PathString("/signout_with_specific_redirect_uri"))
|
||||||
{
|
{
|
||||||
res.SignOut(
|
res.SignOut(
|
||||||
OpenIdConnectAuthenticationDefaults.AuthenticationScheme,
|
OpenIdConnectAuthenticationDefaults.AuthenticationScheme,
|
||||||
new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" });
|
new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" });
|
||||||
}
|
}
|
||||||
else if (handler != null)
|
else if (handler != null)
|
||||||
|
|
@ -240,6 +231,14 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
services =>
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,14 +105,6 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
{
|
{
|
||||||
return TestServer.Create(app =>
|
return TestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseServices(services =>
|
|
||||||
{
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.Configure<ExternalAuthenticationOptions>(options =>
|
|
||||||
{
|
|
||||||
options.SignInScheme = "External";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
app.UseCookieAuthentication(options =>
|
app.UseCookieAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.AuthenticationScheme = "External";
|
options.AuthenticationScheme = "External";
|
||||||
|
|
@ -128,6 +120,14 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
services =>
|
||||||
|
{
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||||
|
{
|
||||||
|
options.SignInScheme = "External";
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue