React to Options, Configure => Add, Cookie changes

UseCookie now has an overload which takes an instance of CookieOptions
This commit is contained in:
Hao Kung 2015-09-02 14:13:16 -07:00
parent bcf8a45340
commit bf2b771eab
30 changed files with 109 additions and 229 deletions

View File

@ -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"));

View File

@ -20,13 +20,10 @@ namespace Microsoft.AspNet.Builder
/// <param name="configureOptions">Used to configure the options for the middleware</param>
/// <param name="optionsName">The name of the options class that controls the middleware behavior, null will use the default options</param>
/// <returns>The original app parameter</returns>
public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action<CookieAuthenticationOptions> configureOptions = null, string optionsName = "")
public static IApplicationBuilder UseCookieAuthentication([NotNull] this IApplicationBuilder app, Action<CookieAuthenticationOptions> configureOptions = null)
{
return app.UseMiddleware<CookieAuthenticationMiddleware>(
new ConfigureOptions<CookieAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<CookieAuthenticationOptions>(configureOptions ?? (o => { })));
}
/// <summary>

View File

@ -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
{
/// <summary>
/// Contains the options used by the CookiesAuthenticationMiddleware
/// </summary>
public class CookieAuthenticationOptions : AuthenticationOptions
public class CookieAuthenticationOptions : AuthenticationOptions, IOptions<CookieAuthenticationOptions>
{
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.
/// </summary>
public IAuthenticationSessionStore SessionStore { get; set; }
CookieAuthenticationOptions IOptions<CookieAuthenticationOptions>.Value
{
get
{
return this;
}
}
}
}

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class CookieServiceCollectionExtensions
{
public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<CookieAuthenticationOptions> configure)
public static IServiceCollection AddCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<CookieAuthenticationOptions> configure)
{
return services.ConfigureCookieAuthentication(configure, optionsName: "");
return services.Configure(configure);
}
public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<CookieAuthenticationOptions> 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<CookieAuthenticationOptions>(config, optionsName);
return services.Configure<CookieAuthenticationOptions>(config);
}
}
}

View File

@ -18,13 +18,10 @@ namespace Microsoft.AspNet.Builder
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param>
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookAuthenticationOptions> configureOptions = null, string optionsName = "")
public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookAuthenticationOptions> configureOptions = null)
{
return app.UseMiddleware<FacebookAuthenticationMiddleware>(
new ConfigureOptions<FacebookAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<FacebookAuthenticationOptions>(configureOptions ?? (o => { })));
}
}
}

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class FacebookServiceCollectionExtensions
{
public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> configure)
public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> configure)
{
return services.ConfigureFacebookAuthentication(configure, optionsName: "");
return services.Configure(configure);
}
public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> 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<FacebookAuthenticationOptions>(config, optionsName);
return services.Configure<FacebookAuthenticationOptions>(config);
}
}
}

View File

@ -23,10 +23,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action<GoogleAuthenticationOptions> configureOptions = null, string optionsName = "")
{
return app.UseMiddleware<GoogleAuthenticationMiddleware>(
new ConfigureOptions<GoogleAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<GoogleAuthenticationOptions>(configureOptions ?? (o => { })));
}
}
}

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class GoogleServiceCollectionExtensions
{
public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> configure)
public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> configure)
{
return services.ConfigureGoogleAuthentication(configure, optionsName: "");
return services.Configure(configure);
}
public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> 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<GoogleAuthenticationOptions>(config, optionsName);
return services.Configure<GoogleAuthenticationOptions>(config);
}
}
}

View File

@ -27,10 +27,7 @@ namespace Microsoft.AspNet.Builder
public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action<JwtBearerAuthenticationOptions> configureOptions = null, string optionsName = "")
{
return app.UseMiddleware<JwtBearerAuthenticationMiddleware>(
new ConfigureOptions<JwtBearerAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<JwtBearerAuthenticationOptions>(configureOptions ?? (o => { })));
}
}
}

View File

@ -15,22 +15,12 @@ namespace Microsoft.Framework.DependencyInjection
{
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerAuthenticationOptions> configure)
{
return services.ConfigureJwtBearerAuthentication(configure, optionsName: "");
}
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerAuthenticationOptions> 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<JwtBearerAuthenticationOptions>(config, optionsName);
return services.ConfigureJwtBearerAuthentication(config);
}
}
}

View File

@ -13,13 +13,10 @@ namespace Microsoft.AspNet.Builder
/// </summary>
public static class MicrosoftAccountAuthenticationExtensions
{
public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountAuthenticationOptions> configureOptions = null, string optionsName = "")
public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountAuthenticationOptions> configureOptions = null)
{
return app.UseMiddleware<MicrosoftAccountAuthenticationMiddleware>(
new ConfigureOptions<MicrosoftAccountAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<MicrosoftAccountAuthenticationOptions>(configureOptions ?? (o => { })));
}
}
}

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class MicrosoftAccountServiceCollectionExtensions
{
public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> configure)
public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> configure)
{
return services.ConfigureMicrosoftAccountAuthentication(configure, optionsName: "");
return services.Configure(configure);
}
public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> 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<MicrosoftAccountAuthenticationOptions>(config, optionsName);
return services.Configure<MicrosoftAccountAuthenticationOptions>(config);
}
}
}

View File

@ -30,10 +30,7 @@ namespace Microsoft.AspNet.Builder
{
configureOptions(options);
}
})
{
Name = authenticationScheme,
});
}));
}
}
}

View File

@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
if (string.IsNullOrEmpty(Options.SignInScheme))
{
Options.SignInScheme = sharedOptions.Options.SignInScheme;
Options.SignInScheme = sharedOptions.Value.SignInScheme;
}
}

View File

@ -18,13 +18,10 @@ namespace Microsoft.AspNet.Builder
/// <param name="app">The application builder</param>
/// <param name="options">Options which control the processing of the OpenIdConnect protocol and token validation.</param>
/// <returns>The application builder</returns>
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectAuthenticationOptions> configureOptions = null, string optionsName = "")
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectAuthenticationOptions> configureOptions = null)
{
return app.UseMiddleware<OpenIdConnectAuthenticationMiddleware>(
new ConfigureOptions<OpenIdConnectAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<OpenIdConnectAuthenticationOptions>(configureOptions ?? (o => { })));
}
/// <summary>

View File

@ -49,9 +49,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
ConfigureOptions<OpenIdConnectAuthenticationOptions> 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)

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class OpenIdConnectServiceCollectionExtensions
{
public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OpenIdConnectAuthenticationOptions> configure)
public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OpenIdConnectAuthenticationOptions> configure)
{
return ConfigureOpenIdConnectAuthentication(services, configure, null);
return services.Configure(configure);
}
public static IServiceCollection ConfigureOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OpenIdConnectAuthenticationOptions> 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<OpenIdConnectAuthenticationOptions>(config, optionsName);
return services.Configure<OpenIdConnectAuthenticationOptions>(config);
}
}
}

View File

@ -13,13 +13,10 @@ namespace Microsoft.AspNet.Builder
/// </summary>
public static class TwitterAppBuilderExtensions
{
public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterAuthenticationOptions> configureOptions = null, string optionsName = "")
public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterAuthenticationOptions> configureOptions = null)
{
return app.UseMiddleware<TwitterAuthenticationMiddleware>(
new ConfigureOptions<TwitterAuthenticationOptions>(configureOptions ?? (o => { }))
{
Name = optionsName
});
new ConfigureOptions<TwitterAuthenticationOptions>(configureOptions ?? (o => { })));
}
}
}

View File

@ -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))
{

View File

@ -13,24 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
public static class TwitterAuthenticationExtensions
{
public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> configure)
public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> configure)
{
return services.ConfigureTwitterAuthentication(configure, optionsName: "");
return services.Configure(configure);
}
public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> 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<TwitterAuthenticationOptions>(config, optionsName);
return services.Configure<TwitterAuthenticationOptions>(config);
}
}
}

View File

@ -23,14 +23,10 @@ namespace Microsoft.AspNet.Authentication
[NotNull] IUrlEncoder encoder,
ConfigureOptions<TOptions> 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;

View File

@ -24,17 +24,17 @@ namespace Microsoft.Framework.DependencyInjection
return services.AddAuthentication();
}
public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Action<ClaimsTransformationOptions> configure)
public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Action<ClaimsTransformationOptions> configure)
{
return services.Configure(configure);
}
public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func<ClaimsPrincipal, ClaimsPrincipal> transform)
public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func<ClaimsPrincipal, ClaimsPrincipal> transform)
{
return services.Configure<ClaimsTransformationOptions>(o => o.Transformer = new ClaimsTransformer { TransformSyncDelegate = transform });
}
public static IServiceCollection ConfigureClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func<ClaimsPrincipal, Task<ClaimsPrincipal>> asyncTransform)
public static IServiceCollection AddClaimsTransformation([NotNull] this IServiceCollection services, [NotNull] Func<ClaimsPrincipal, Task<ClaimsPrincipal>> asyncTransform)
{
return services.Configure<ClaimsTransformationOptions>(o => o.Transformer = new ClaimsTransformer { TransformAsyncDelegate = asyncTransform });
}

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Builder
/// <returns>The original app parameter</returns>
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app)
{
return app.UseClaimsTransformation(configureOptions: o => { }, optionsName: string.Empty);
return app.UseClaimsTransformation(configureOptions: o => { });
}
/// <summary>
@ -30,21 +30,9 @@ namespace Microsoft.AspNet.Builder
/// <param name="configureOptions">Used to configure the options for the middleware</param>
/// <returns>The original app parameter</returns>
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action<ClaimsTransformationOptions> configureOptions)
{
return app.UseClaimsTransformation(configureOptions: configureOptions, optionsName: string.Empty);
}
/// <summary>
/// Adds a claims transformation middleware to your web application pipeline.
/// </summary>
/// <param name="app">The IApplicationBuilder passed to your configuration method</param>
/// <param name="configureOptions">Used to configure the options for the middleware</param>
/// <param name="optionsName">The name of the options class that controls the middleware behavior, null will use the default options</param>
/// <returns>The original app parameter</returns>
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, [NotNull] Action<ClaimsTransformationOptions> configureOptions, [NotNull] string optionsName)
{
return app.UseMiddleware<ClaimsTransformationMiddleware>(
new ConfigureOptions<ClaimsTransformationOptions>(configureOptions) { Name = optionsName });
new ConfigureOptions<ClaimsTransformationOptions>(configureOptions));
}
}
}

View File

@ -18,14 +18,10 @@ namespace Microsoft.AspNet.Authentication
[NotNull] IOptions<ClaimsTransformationOptions> options,
ConfigureOptions<ClaimsTransformationOptions> 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;
}

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authorization
public DefaultAuthorizationService(IOptions<AuthorizationOptions> options, IEnumerable<IAuthorizationHandler> handlers)
{
_handlers = handlers.ToArray();
_options = options.Options;
_options = options.Value;
}
public async Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)

View File

@ -10,11 +10,6 @@ namespace Microsoft.Framework.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection ConfigureAuthorization([NotNull] this IServiceCollection services, [NotNull] Action<AuthorizationOptions> 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<AuthorizationOptions> configureOptions)
public static IServiceCollection AddAuthorization([NotNull] this IServiceCollection services, [NotNull] Action<AuthorizationOptions> configure)
{
services.ConfigureAuthorization(configureOptions);
services.Configure(configure);
return services.AddAuthorization();
}
}

View File

@ -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;

View File

@ -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<SharedAuthenticationOptions>(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<SharedAuthenticationOptions>(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";

View File

@ -600,12 +600,8 @@ namespace Microsoft.AspNet.Authentication.Google
},
services =>
{
services.AddAuthentication();
services.Configure<SharedAuthenticationOptions>(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"));

View File

@ -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<InvalidOperationException>(() => 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<IAuthorizationHandler, CustomHandler>();
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)));
});