diff --git a/samples/IdentitySample.Mvc/Models/SampleData.cs b/samples/IdentitySample.Mvc/Models/SampleData.cs
index a1c8e624c8..929785a2f5 100644
--- a/samples/IdentitySample.Mvc/Models/SampleData.cs
+++ b/samples/IdentitySample.Mvc/Models/SampleData.cs
@@ -29,7 +29,7 @@ namespace IdentitySample.Models
///
private static async Task CreateAdminUser(IServiceProvider serviceProvider)
{
- var options = serviceProvider.GetRequiredService>().Options;
+ var options = serviceProvider.GetRequiredService>().Value;
const string adminRole = "Administrator";
var userManager = serviceProvider.GetRequiredService>();
diff --git a/src/Microsoft.AspNet.Identity/BuilderExtensions.cs b/src/Microsoft.AspNet.Identity/BuilderExtensions.cs
index 2f5159da32..a37afaafe4 100644
--- a/src/Microsoft.AspNet.Identity/BuilderExtensions.cs
+++ b/src/Microsoft.AspNet.Identity/BuilderExtensions.cs
@@ -5,6 +5,7 @@ using System;
using Microsoft.AspNet.Identity;
using Microsoft.Framework.DependencyInjection;
+using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Builder
{
@@ -31,10 +32,11 @@ namespace Microsoft.AspNet.Builder
throw new InvalidOperationException(Resources.MustCallAddIdentity);
}
- app.UseCookieAuthentication(null, IdentityOptions.ExternalCookieAuthenticationScheme);
- app.UseCookieAuthentication(null, IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme);
- app.UseCookieAuthentication(null, IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme);
- app.UseCookieAuthentication(null, IdentityOptions.ApplicationCookieAuthenticationScheme);
+ var options = app.ApplicationServices.GetRequiredService>().Value;
+ app.UseCookieAuthentication(options.Cookies.ExternalCookie);
+ app.UseCookieAuthentication(options.Cookies.TwoFactorRememberMeCookie);
+ app.UseCookieAuthentication(options.Cookies.TwoFactorUserIdCookie);
+ app.UseCookieAuthentication(options.Cookies.ApplicationCookie);
return app;
}
}
diff --git a/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs b/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs
index 90b7821565..1d5ad76ecb 100644
--- a/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs
+++ b/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs
@@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Identity
{
throw new ArgumentNullException(nameof(dataProtectionProvider));
}
- Options = options?.Options ?? new DataProtectionTokenProviderOptions();
+ Options = options?.Value ?? new DataProtectionTokenProviderOptions();
// Use the Name as the purpose which should usually be distinct from others
Protector = dataProtectionProvider.CreateProtector(Name ?? "DataProtectorTokenProvider");
}
diff --git a/src/Microsoft.AspNet.Identity/EmailTokenProvider.cs b/src/Microsoft.AspNet.Identity/EmailTokenProvider.cs
index 31d91de53a..6ab61a2a25 100644
--- a/src/Microsoft.AspNet.Identity/EmailTokenProvider.cs
+++ b/src/Microsoft.AspNet.Identity/EmailTokenProvider.cs
@@ -1,23 +1,7 @@
-using System;
using System.Threading.Tasks;
-using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Identity
{
- ///
- /// Options for the class.
- ///
- public class EmailTokenProviderOptions
- {
- ///
- /// Gets or sets the unique name used for an instance of .
- ///
- ///
- /// The unique name used for an instance of .
- ///
- public string Name { get; set; } = "Email";
- }
-
///
/// TokenProvider that generates tokens from the user's security stamp and notifies a user via email.
///
@@ -25,36 +9,6 @@ namespace Microsoft.AspNet.Identity
public class EmailTokenProvider : TotpSecurityStampBasedTokenProvider
where TUser : class
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The configured .
- /// The unique name for this instance of .
- public EmailTokenProvider(IOptions options, string name = "")
- {
- if (options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
- Options = options.GetNamedOptions(name);
- }
-
- ///
- /// Gets the options for this instance of .
- ///
- ///
- /// The options for this instance of .
- ///
- public EmailTokenProviderOptions Options { get; private set; }
-
- ///
- /// Gets the unique name for this instance of .
- ///
- ///
- /// The unique name for this instance of .
- ///
- public override string Name { get { return Options.Name; } }
-
///
/// Checks if a two factor authentication token can be generated for the specified .
///
diff --git a/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs b/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs
index ce9ee317be..96d9b5fec4 100644
--- a/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs
+++ b/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs
@@ -11,12 +11,6 @@ namespace Microsoft.AspNet.Identity
/// The type encapsulating a user.
public interface IUserTokenProvider where TUser : class
{
- ///
- /// Gets the name of the token provider.
- ///
- /// The name of the token provider.
- string Name { get; }
-
///
/// Generates a token for the specified and , as an asynchronous operation.
///
diff --git a/src/Microsoft.AspNet.Identity/IdentityBuilder.cs b/src/Microsoft.AspNet.Identity/IdentityBuilder.cs
index 09d6d2b81b..c1dbafd5f6 100644
--- a/src/Microsoft.AspNet.Identity/IdentityBuilder.cs
+++ b/src/Microsoft.AspNet.Identity/IdentityBuilder.cs
@@ -121,20 +121,31 @@ namespace Microsoft.AspNet.Identity
/// Adds a token provider.
///
/// The type of the token provider to add.
+ /// The name of the provider to add.
/// The .
- public virtual IdentityBuilder AddTokenProvider() where TProvider : class
+ public virtual IdentityBuilder AddTokenProvider(string providerName) where TProvider : class
{
- return AddTokenProvider(typeof(TProvider));
+ return AddTokenProvider(providerName, typeof(TProvider));
}
///
/// Adds a token provider for the .
///
+ /// The name of the provider to add.
/// The type of the to add.
/// The .
- public virtual IdentityBuilder AddTokenProvider(Type provider)
+ public virtual IdentityBuilder AddTokenProvider(string providerName, Type provider)
{
- return AddScoped(typeof(IUserTokenProvider<>).MakeGenericType(UserType), provider);
+ if (!typeof(IUserTokenProvider<>).MakeGenericType(UserType).GetTypeInfo().IsAssignableFrom(provider.GetTypeInfo()))
+ {
+ throw new InvalidOperationException(Resources.FormatInvalidManagerType(provider.Name, "IUserTokenProvider", UserType.Name));
+ }
+ Services.Configure(options =>
+ {
+ options.Tokens.ProviderMap[providerName] = new TokenProviderDescriptor(provider);
+ });
+ Services.AddTransient(provider);
+ return this;
}
///
@@ -143,14 +154,12 @@ namespace Microsoft.AspNet.Identity
/// The .
public virtual IdentityBuilder AddDefaultTokenProviders()
{
- Services.Configure(options =>
- {
- options.Name = Resources.DefaultTokenProvider;
- });
-
- return AddTokenProvider(typeof(DataProtectorTokenProvider<>).MakeGenericType(UserType))
- .AddTokenProvider(typeof(PhoneNumberTokenProvider<>).MakeGenericType(UserType))
- .AddTokenProvider(typeof(EmailTokenProvider<>).MakeGenericType(UserType));
+ var dataProtectionProviderType = typeof(DataProtectorTokenProvider<>).MakeGenericType(UserType);
+ var phoneNumberProviderType = typeof(PhoneNumberTokenProvider<>).MakeGenericType(UserType);
+ var emailTokenProviderType = typeof(EmailTokenProvider<>).MakeGenericType(UserType);
+ return AddTokenProvider(TokenOptions.DefaultProvider, dataProtectionProviderType)
+ .AddTokenProvider(TokenOptions.DefaultEmailProvider, emailTokenProviderType)
+ .AddTokenProvider(TokenOptions.DefaultPhoneProvider, phoneNumberProviderType);
}
///
diff --git a/src/Microsoft.AspNet.Identity/IdentityCookieOptions.cs b/src/Microsoft.AspNet.Identity/IdentityCookieOptions.cs
new file mode 100644
index 0000000000..f435203ecb
--- /dev/null
+++ b/src/Microsoft.AspNet.Identity/IdentityCookieOptions.cs
@@ -0,0 +1,86 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using Microsoft.AspNet.Authentication.Cookies;
+using Microsoft.AspNet.Http;
+
+namespace Microsoft.AspNet.Identity
+{
+ ///
+ /// Represents all the options you can use to configure the cookies middleware uesd by the identity system.
+ ///
+ public class IdentityCookieOptions
+ {
+ public IdentityCookieOptions()
+ {
+ // Configure all of the cookie middlewares
+ ApplicationCookie = new CookieAuthenticationOptions
+ {
+ AuthenticationScheme = ApplicationCookieAuthenticationScheme,
+ AutomaticAuthentication = true,
+ LoginPath = new PathString("/Account/Login"),
+ Notifications = new CookieAuthenticationNotifications
+ {
+ OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
+ }
+ };
+
+ ExternalCookie = new CookieAuthenticationOptions
+ {
+ AuthenticationScheme = ExternalCookieAuthenticationScheme,
+ CookieName = ExternalCookieAuthenticationScheme,
+ ExpireTimeSpan = TimeSpan.FromMinutes(5)
+ };
+
+ TwoFactorRememberMeCookie = new CookieAuthenticationOptions
+ {
+ AuthenticationScheme = TwoFactorRememberMeCookieAuthenticationScheme,
+ CookieName = TwoFactorRememberMeCookieAuthenticationScheme
+ };
+
+ TwoFactorUserIdCookie = new CookieAuthenticationOptions
+ {
+ AuthenticationScheme = TwoFactorUserIdCookieAuthenticationScheme,
+ CookieName = TwoFactorUserIdCookieAuthenticationScheme,
+ ExpireTimeSpan = TimeSpan.FromMinutes(5)
+ };
+
+ }
+
+ public CookieAuthenticationOptions ApplicationCookie { get; set; }
+ public CookieAuthenticationOptions ExternalCookie { get; set; }
+ public CookieAuthenticationOptions TwoFactorRememberMeCookie { get; set; }
+ public CookieAuthenticationOptions TwoFactorUserIdCookie { get; set; }
+
+ ///
+ /// Gets or sets the scheme used to identify application authentication cookies.
+ ///
+ /// The scheme used to identify application authentication cookies.
+ public string ApplicationCookieAuthenticationScheme { get; set; } = ApplicationCookieAuthenticationType;
+
+ ///
+ /// Gets or sets the scheme used to identify external authentication cookies.
+ ///
+ /// The scheme used to identify external authentication cookies.
+ public string ExternalCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".External.AuthType";
+
+ ///
+ /// Gets or sets the scheme used to identify Two Factor authentication cookies for round tripping user identities.
+ ///
+ /// The scheme used to identify user identity 2fa authentication cookies.
+ public string TwoFactorUserIdCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".TwoFactorUserId.AuthType";
+
+ ///
+ /// Gets or sets the scheme used to identify Two Factor authentication cookies for saving the Remember Me state.
+ ///
+ /// The scheme used to identify remember me application authentication cookies.
+ public string TwoFactorRememberMeCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".TwoFactorRemeberMe.AuthType";
+
+ ///
+ /// Gets or sets the authentication type used when constructing an from an application cookie.
+ ///
+ /// The authentication type used when constructing an from an application cookie.
+ public static string ApplicationCookieAuthenticationType { get; set; } = typeof(IdentityCookieOptions).Namespace + ".Application.AuthType";
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/IdentityOptions.cs b/src/Microsoft.AspNet.Identity/IdentityOptions.cs
index 932d4e6b1c..24f716c42a 100644
--- a/src/Microsoft.AspNet.Identity/IdentityOptions.cs
+++ b/src/Microsoft.AspNet.Identity/IdentityOptions.cs
@@ -6,7 +6,7 @@ using System;
namespace Microsoft.AspNet.Identity
{
///
- /// Represents all the options you can used to configure the identity system.
+ /// Represents all the options you can use to configure the identity system.
///
public class IdentityOptions
{
@@ -50,6 +50,22 @@ namespace Microsoft.AspNet.Identity
///
public SignInOptions SignIn { get; set; } = new SignInOptions();
+ ///
+ /// Gets or sets the for the identity system.
+ ///
+ ///
+ /// The for the identity system.
+ ///
+ public IdentityCookieOptions Cookies { get; set; } = new IdentityCookieOptions();
+
+ ///
+ /// Gets or sets the for the identity system.
+ ///
+ ///
+ /// The for the identity system.
+ ///
+ public TokenOptions Tokens { get; set; } = new TokenOptions();
+
///
/// Gets or sets the after which security stamps are re-validated.
///
@@ -57,78 +73,5 @@ namespace Microsoft.AspNet.Identity
/// The after which security stamps are re-validated.
///
public TimeSpan SecurityStampValidationInterval { get; set; } = TimeSpan.FromMinutes(30);
-
- ///
- /// Gets or sets the used to generate tokens used in account confirmation emails.
- ///
- ///
- /// The used to generate tokens used in account confirmation emails.
- ///
- public string EmailConfirmationTokenProvider { get; set; } = Resources.DefaultTokenProvider;
-
- ///
- /// Gets or sets the used to generate tokens used in password reset emails.
- ///
- ///
- /// The used to generate tokens used in password reset emails.
- ///
- public string PasswordResetTokenProvider { get; set; } = Resources.DefaultTokenProvider;
-
- ///
- /// Gets or sets the used to generate tokens used in email change confirmation emails.
- ///
- ///
- /// The used to generate tokens used in email change confirmation emails.
- ///
- public string ChangeEmailTokenProvider { get; set; } = Resources.DefaultTokenProvider;
-
- ///
- /// Gets or sets the scheme used to identify application authentication cookies.
- ///
- /// The scheme used to identify application authentication cookies.
- public static string ApplicationCookieAuthenticationScheme { get; set; } = typeof(IdentityOptions).Namespace + ".Application";
-
- ///
- /// Gets or sets the scheme used to identify external authentication cookies.
- ///
- /// The scheme used to identify external authentication cookies.
- public static string ExternalCookieAuthenticationScheme { get; set; } = typeof(IdentityOptions).Namespace + ".External";
-
- ///
- /// Gets or sets the scheme used to identify Two Factor authentication cookies for round tripping user identities.
- ///
- /// The scheme used to identify user identity 2fa authentication cookies.
- public static string TwoFactorUserIdCookieAuthenticationScheme { get; set; } = typeof(IdentityOptions).Namespace + ".TwoFactorUserId";
-
- ///
- /// Gets or sets the scheme used to identify Two Factor authentication cookies for saving the Remember Me state.
- ///
- /// The scheme used to identify remember me application authentication cookies.
- public static string TwoFactorRememberMeCookieAuthenticationScheme { get; set; } = typeof(IdentityOptions).Namespace + ".TwoFactorRememberMe";
-
-
- ///
- /// Gets or sets the authentication type used when constructing an from an application cookie.
- ///
- /// The authentication type used when constructing an from an application cookie.
- public static string ApplicationCookieAuthenticationType { get; set; } = typeof(IdentityOptions).Namespace + ".Application.AuthType";
-
- ///
- /// Gets or sets the authentication type used when constructing an from an external identity cookie.
- ///
- /// The authentication type used when constructing an from an external identity cookie.
- public static string ExternalCookieAuthenticationType { get; set; } = typeof(IdentityOptions).Namespace + ".External.AuthType";
-
- ///
- /// Gets or sets the authentication type used when constructing an from an two factor authentication cookie.
- ///
- /// The authentication type used when constructing an from an two factor authentication cookie.
- public static string TwoFactorUserIdCookieAuthenticationType { get; set; } = typeof(IdentityOptions).Namespace + ".TwoFactorUserId.AuthType";
-
- ///
- /// Gets or sets the authentication type used when constructing an from an two factor remember me authentication cookie.
- ///
- /// The authentication type used when constructing an from an two factor remember me authentication cookie.
- public static string TwoFactorRememberMeCookieAuthenticationType { get; set; } = typeof(IdentityOptions).Namespace + ".TwoFactorRemeberMe.AuthType";
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs
index 303144b717..1762e5c11e 100644
--- a/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs
+++ b/src/Microsoft.AspNet.Identity/IdentityServiceCollectionExtensions.cs
@@ -2,10 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using Microsoft.AspNet.Http;
-using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Authentication;
-using Microsoft.AspNet.Authentication.Cookies;
+using Microsoft.AspNet.Identity;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection.Extensions;
@@ -16,39 +14,6 @@ namespace Microsoft.Framework.DependencyInjection
///
public static class IdentityServiceCollectionExtensions
{
- ///
- /// Configures a set of for the application
- ///
- /// The services available in the application.
- /// An action to configure the .
- /// The instance this method extends.
- public static IServiceCollection ConfigureIdentity(this IServiceCollection services, Action setupAction)
- {
- return services.Configure(setupAction);
- }
-
- ///
- /// Configures a set of for the application
- ///
- /// The services available in the application.
- /// The configuration for the .
- /// The instance this method extends.
- public static IServiceCollection ConfigureIdentity(this IServiceCollection services, IConfiguration config)
- {
- return services.Configure(config);
- }
-
- ///
- /// Configures a set of for the application
- ///
- /// The services available in the application.
- /// An action to configure the .
- /// The instance this method extends.
- public static IServiceCollection ConfigureIdentityApplicationCookie(this IServiceCollection services, Action setupAction)
- {
- return services.ConfigureCookieAuthentication(setupAction, IdentityOptions.ApplicationCookieAuthenticationScheme);
- }
-
///
/// Adds the default identity system configuration for the specified User and Role types.
///
@@ -99,43 +64,14 @@ namespace Microsoft.Framework.DependencyInjection
if (setupAction != null)
{
- services.ConfigureIdentity(setupAction);
+ services.Configure(setupAction);
}
services.Configure(options =>
{
- options.SignInScheme = IdentityOptions.ExternalCookieAuthenticationScheme;
+ // This is the Default value for ExternalCookieAuthenticationScheme
+ options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme;
});
- // Configure all of the cookie middlewares
- services.ConfigureIdentityApplicationCookie(options =>
- {
- options.AuthenticationScheme = IdentityOptions.ApplicationCookieAuthenticationScheme;
- options.AutomaticAuthentication = true;
- options.LoginPath = new PathString("/Account/Login");
- options.Notifications = new CookieAuthenticationNotifications
- {
- OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
- };
- });
-
- services.ConfigureCookieAuthentication(options =>
- {
- options.AuthenticationScheme = IdentityOptions.ExternalCookieAuthenticationScheme;
- options.CookieName = IdentityOptions.ExternalCookieAuthenticationScheme;
- options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
- }, IdentityOptions.ExternalCookieAuthenticationScheme);
- services.ConfigureCookieAuthentication(options =>
- {
- options.AuthenticationScheme = IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme;
- options.CookieName = IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme;
- }, IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme);
- services.ConfigureCookieAuthentication(options =>
- {
- options.AuthenticationScheme = IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme;
- options.CookieName = IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme;
- options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
- }, IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme);
-
return new IdentityBuilder(typeof(TUser), typeof(TRole), services);
}
}
diff --git a/src/Microsoft.AspNet.Identity/PasswordHasher.cs b/src/Microsoft.AspNet.Identity/PasswordHasher.cs
index 31397802d9..cd53f24bb5 100644
--- a/src/Microsoft.AspNet.Identity/PasswordHasher.cs
+++ b/src/Microsoft.AspNet.Identity/PasswordHasher.cs
@@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity
/// The options for this instance.
public PasswordHasher(IOptions optionsAccessor = null)
{
- var options = optionsAccessor?.Options ?? new PasswordHasherOptions();
+ var options = optionsAccessor?.Value ?? new PasswordHasherOptions();
_compatibilityMode = options.CompatibilityMode;
switch (_compatibilityMode)
diff --git a/src/Microsoft.AspNet.Identity/PhoneNumberTokenProvider.cs b/src/Microsoft.AspNet.Identity/PhoneNumberTokenProvider.cs
index f90b3a02f3..20436faa54 100644
--- a/src/Microsoft.AspNet.Identity/PhoneNumberTokenProvider.cs
+++ b/src/Microsoft.AspNet.Identity/PhoneNumberTokenProvider.cs
@@ -1,23 +1,8 @@
using System;
using System.Threading.Tasks;
-using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Identity
{
- ///
- /// Encapsulations options for a .
- ///
- public class PhoneNumberTokenProviderOptions
- {
- ///
- /// Gets or sets the name for the .
- ///
- ///
- /// The name for the .
- ///
- public string Name { get; set; } = "Phone";
- }
-
///
/// Represents a token provider that generates tokens from a user's security stamp and
/// sends them to the user via their phone number.
@@ -26,31 +11,6 @@ namespace Microsoft.AspNet.Identity
public class PhoneNumberTokenProvider : TotpSecurityStampBasedTokenProvider
where TUser : class
{
- ///
- /// Creates a new instance of with the specified .
- ///
- /// The options to use for the created instance of a .
- public PhoneNumberTokenProvider(IOptions options)
- {
- if (options == null || options.Options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
- Options = options.Options;
- }
-
- ///
- /// Gets the options for this instance of .
- ///
- /// The options for this instance of .
- public PhoneNumberTokenProviderOptions Options { get; private set; }
-
- ///
- /// Gets the name for this instance of .
- ///
- /// The name for this instance of .
- public override string Name { get { return Options.Name; } }
-
///
/// Returns a flag indicating whether the token provider can generate a token suitable for two factor authentication token for
/// the specified .
diff --git a/src/Microsoft.AspNet.Identity/PrincipalExtensions.cs b/src/Microsoft.AspNet.Identity/PrincipalExtensions.cs
index 73ab8d1537..cf6eb29667 100644
--- a/src/Microsoft.AspNet.Identity/PrincipalExtensions.cs
+++ b/src/Microsoft.AspNet.Identity/PrincipalExtensions.cs
@@ -53,7 +53,7 @@ namespace System.Security.Claims
throw new ArgumentNullException(nameof(principal));
}
return principal?.Identities != null &&
- principal.Identities.Any(i => i.AuthenticationType == IdentityOptions.ApplicationCookieAuthenticationType);
+ principal.Identities.Any(i => i.AuthenticationType == IdentityCookieOptions.ApplicationCookieAuthenticationType);
}
///
diff --git a/src/Microsoft.AspNet.Identity/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Identity/Properties/Resources.Designer.cs
index 55c081d61c..094c0fe0f8 100644
--- a/src/Microsoft.AspNet.Identity/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNet.Identity/Properties/Resources.Designer.cs
@@ -42,22 +42,6 @@ namespace Microsoft.AspNet.Identity
return GetString("DefaultError");
}
- ///
- /// Default Token Provider
- ///
- internal static string DefaultTokenProvider
- {
- get { return GetString("DefaultTokenProvider"); }
- }
-
- ///
- /// Default Token Provider
- ///
- internal static string FormatDefaultTokenProvider()
- {
- return GetString("DefaultTokenProvider");
- }
-
///
/// Email '{0}' is already taken.
///
@@ -123,7 +107,7 @@ namespace Microsoft.AspNet.Identity
}
///
- /// Type {0} must be derived from {1}<{2}>.
+ /// Type {0} must derive from {1}<{2}>.
///
internal static string InvalidManagerType
{
@@ -131,7 +115,7 @@ namespace Microsoft.AspNet.Identity
}
///
- /// Type {0} must be derived from {1}<{2}>.
+ /// Type {0} must derive from {1}<{2}>.
///
internal static string FormatInvalidManagerType(object p0, object p1, object p2)
{
diff --git a/src/Microsoft.AspNet.Identity/Resources.resx b/src/Microsoft.AspNet.Identity/Resources.resx
index 87dbde9344..feda1883d2 100644
--- a/src/Microsoft.AspNet.Identity/Resources.resx
+++ b/src/Microsoft.AspNet.Identity/Resources.resx
@@ -125,10 +125,6 @@
An unknown failure has occured.Default identity result error message
-
- Default Token Provider
- Name of the default token provider
-
Email '{0}' is already taken.Error for duplicate emails
diff --git a/src/Microsoft.AspNet.Identity/SecurityStampValidator.cs b/src/Microsoft.AspNet.Identity/SecurityStampValidator.cs
index ba9b6d7ca7..5ec5dca3fc 100644
--- a/src/Microsoft.AspNet.Identity/SecurityStampValidator.cs
+++ b/src/Microsoft.AspNet.Identity/SecurityStampValidator.cs
@@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Identity
{
var timeElapsed = currentUtc.Subtract(issuedUtc.Value);
var accessor = context.HttpContext.RequestServices.GetRequiredService>();
- validate = timeElapsed > accessor.Options.SecurityStampValidationInterval;
+ validate = timeElapsed > accessor.Value.SecurityStampValidationInterval;
}
if (validate)
{
diff --git a/src/Microsoft.AspNet.Identity/SignInManager.cs b/src/Microsoft.AspNet.Identity/SignInManager.cs
index 2f9bee50b7..addbea4195 100644
--- a/src/Microsoft.AspNet.Identity/SignInManager.cs
+++ b/src/Microsoft.AspNet.Identity/SignInManager.cs
@@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Identity
UserManager = userManager;
Context = contextAccessor.HttpContext;
ClaimsFactory = claimsFactory;
- Options = optionsAccessor?.Options ?? new IdentityOptions();
+ Options = optionsAccessor?.Value ?? new IdentityOptions();
Logger = logger;
}
@@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Identity
/// The task object representing the asynchronous operation.
public virtual async Task RefreshSignInAsync(TUser user)
{
- var auth = new AuthenticateContext(IdentityOptions.ApplicationCookieAuthenticationScheme);
+ var auth = new AuthenticateContext(Options.Cookies.ApplicationCookieAuthenticationScheme);
await Context.Authentication.AuthenticateAsync(auth);
var authenticationMethod = auth.Principal?.FindFirstValue(ClaimTypes.AuthenticationMethod);
await SignInAsync(user, new AuthenticationProperties(auth.Properties), authenticationMethod);
@@ -142,7 +142,7 @@ namespace Microsoft.AspNet.Identity
{
userPrincipal.Identities.First().AddClaim(new Claim(ClaimTypes.AuthenticationMethod, authenticationMethod));
}
- await Context.Authentication.SignInAsync(IdentityOptions.ApplicationCookieAuthenticationScheme,
+ await Context.Authentication.SignInAsync(Options.Cookies.ApplicationCookieAuthenticationScheme,
userPrincipal,
authenticationProperties ?? new AuthenticationProperties());
}
@@ -152,9 +152,9 @@ namespace Microsoft.AspNet.Identity
///
public virtual async Task SignOutAsync()
{
- await Context.Authentication.SignOutAsync(IdentityOptions.ApplicationCookieAuthenticationScheme);
- await Context.Authentication.SignOutAsync(IdentityOptions.ExternalCookieAuthenticationScheme);
- await Context.Authentication.SignOutAsync(IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme);
+ await Context.Authentication.SignOutAsync(Options.Cookies.ApplicationCookieAuthenticationScheme);
+ await Context.Authentication.SignOutAsync(Options.Cookies.ExternalCookieAuthenticationScheme);
+ await Context.Authentication.SignOutAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
}
///
@@ -260,7 +260,7 @@ namespace Microsoft.AspNet.Identity
public virtual async Task IsTwoFactorClientRememberedAsync(TUser user)
{
var userId = await UserManager.GetUserIdAsync(user);
- var result = await Context.Authentication.AuthenticateAsync(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme);
+ var result = await Context.Authentication.AuthenticateAsync(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme);
return (result != null && result.FindFirstValue(ClaimTypes.Name) == userId);
}
@@ -273,9 +273,9 @@ namespace Microsoft.AspNet.Identity
public virtual async Task RememberTwoFactorClientAsync(TUser user)
{
var userId = await UserManager.GetUserIdAsync(user);
- var rememberBrowserIdentity = new ClaimsIdentity(IdentityOptions.TwoFactorRememberMeCookieAuthenticationType);
+ var rememberBrowserIdentity = new ClaimsIdentity(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme);
rememberBrowserIdentity.AddClaim(new Claim(ClaimTypes.Name, userId));
- await Context.Authentication.SignInAsync(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme,
+ await Context.Authentication.SignInAsync(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme,
new ClaimsPrincipal(rememberBrowserIdentity),
new AuthenticationProperties { IsPersistent = true });
}
@@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Identity
/// The task object representing the asynchronous operation.
public virtual Task ForgetTwoFactorClientAsync()
{
- return Context.Authentication.SignOutAsync(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme);
+ return Context.Authentication.SignOutAsync(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme);
}
///
@@ -325,7 +325,7 @@ namespace Microsoft.AspNet.Identity
// Cleanup external cookie
if (twoFactorInfo.LoginProvider != null)
{
- await Context.Authentication.SignOutAsync(IdentityOptions.ExternalCookieAuthenticationScheme);
+ await Context.Authentication.SignOutAsync(Options.Cookies.ExternalCookieAuthenticationScheme);
}
if (rememberClient)
{
@@ -397,7 +397,7 @@ namespace Microsoft.AspNet.Identity
/// for the sign-in attempt.
public virtual async Task GetExternalLoginInfoAsync(string expectedXsrf = null)
{
- var auth = new AuthenticateContext(IdentityOptions.ExternalCookieAuthenticationScheme);
+ var auth = new AuthenticateContext(Options.Cookies.ExternalCookieAuthenticationScheme);
await Context.Authentication.AuthenticateAsync(auth);
if (auth.Principal == null || auth.Properties == null || !auth.Properties.ContainsKey(LoginProviderKey))
{
@@ -451,9 +451,9 @@ namespace Microsoft.AspNet.Identity
/// The user whose is logging in via 2fa.
/// The 2fa provider.
/// A containing the user 2fa information.
- internal static ClaimsPrincipal StoreTwoFactorInfo(string userId, string loginProvider)
+ internal ClaimsPrincipal StoreTwoFactorInfo(string userId, string loginProvider)
{
- var identity = new ClaimsIdentity(IdentityOptions.TwoFactorUserIdCookieAuthenticationType);
+ var identity = new ClaimsIdentity(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
identity.AddClaim(new Claim(ClaimTypes.Name, userId));
if (loginProvider != null)
{
@@ -462,13 +462,13 @@ namespace Microsoft.AspNet.Identity
return new ClaimsPrincipal(identity);
}
- private static ClaimsIdentity CreateIdentity(TwoFactorAuthenticationInfo info)
+ private ClaimsIdentity CreateIdentity(TwoFactorAuthenticationInfo info)
{
if (info == null)
{
return null;
}
- var identity = new ClaimsIdentity(IdentityOptions.TwoFactorUserIdCookieAuthenticationType);
+ var identity = new ClaimsIdentity(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
identity.AddClaim(new Claim(ClaimTypes.Name, info.UserId));
if (info.LoginProvider != null)
{
@@ -488,14 +488,14 @@ namespace Microsoft.AspNet.Identity
{
// Store the userId for use after two factor check
var userId = await UserManager.GetUserIdAsync(user);
- await Context.Authentication.SignInAsync(IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme, StoreTwoFactorInfo(userId, loginProvider));
+ await Context.Authentication.SignInAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme, StoreTwoFactorInfo(userId, loginProvider));
return SignInResult.TwoFactorRequired;
}
}
// Cleanup external cookie
if (loginProvider != null)
{
- await Context.Authentication.SignOutAsync(IdentityOptions.ExternalCookieAuthenticationScheme);
+ await Context.Authentication.SignOutAsync(Options.Cookies.ExternalCookieAuthenticationScheme);
}
await SignInAsync(user, isPersistent, loginProvider);
return SignInResult.Success;
@@ -503,7 +503,7 @@ namespace Microsoft.AspNet.Identity
private async Task RetrieveTwoFactorInfoAsync()
{
- var result = await Context.Authentication.AuthenticateAsync(IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme);
+ var result = await Context.Authentication.AuthenticateAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
if (result != null)
{
return new TwoFactorAuthenticationInfo
diff --git a/src/Microsoft.AspNet.Identity/TokenOptions.cs b/src/Microsoft.AspNet.Identity/TokenOptions.cs
new file mode 100644
index 0000000000..4b0c94b9a9
--- /dev/null
+++ b/src/Microsoft.AspNet.Identity/TokenOptions.cs
@@ -0,0 +1,44 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Collections.Generic;
+
+namespace Microsoft.AspNet.Identity
+{
+ public class TokenOptions
+ {
+ public static readonly string DefaultProvider = "Default";
+ public static readonly string DefaultEmailProvider = "Email";
+ public static readonly string DefaultPhoneProvider = "Phone";
+
+ ///
+ /// Will be used to construct UserTokenProviders with the key used as the providerName.
+ ///
+ public Dictionary ProviderMap { get; set; } = new Dictionary();
+
+ ///
+ /// Gets or sets the used to generate tokens used in account confirmation emails.
+ ///
+ ///
+ /// The used to generate tokens used in account confirmation emails.
+ ///
+ public string EmailConfirmationTokenProvider { get; set; } = DefaultProvider;
+
+ ///
+ /// Gets or sets the used to generate tokens used in password reset emails.
+ ///
+ ///
+ /// The used to generate tokens used in password reset emails.
+ ///
+ public string PasswordResetTokenProvider { get; set; } = DefaultProvider;
+
+ ///
+ /// Gets or sets the used to generate tokens used in email change confirmation emails.
+ ///
+ ///
+ /// The used to generate tokens used in email change confirmation emails.
+ ///
+ public string ChangeEmailTokenProvider { get; set; } = DefaultProvider;
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/TokenProviderDescriptor.cs b/src/Microsoft.AspNet.Identity/TokenProviderDescriptor.cs
new file mode 100644
index 0000000000..881b0d4c53
--- /dev/null
+++ b/src/Microsoft.AspNet.Identity/TokenProviderDescriptor.cs
@@ -0,0 +1,17 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+
+namespace Microsoft.AspNet.Identity
+{
+ public class TokenProviderDescriptor
+ {
+ public TokenProviderDescriptor(Type type)
+ {
+ ProviderType = type;
+ }
+
+ public Type ProviderType { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/TotpSecurityStampBasedTokenProvider.cs b/src/Microsoft.AspNet.Identity/TotpSecurityStampBasedTokenProvider.cs
index d77872a449..4c7b5ea3f7 100644
--- a/src/Microsoft.AspNet.Identity/TotpSecurityStampBasedTokenProvider.cs
+++ b/src/Microsoft.AspNet.Identity/TotpSecurityStampBasedTokenProvider.cs
@@ -12,12 +12,6 @@ namespace Microsoft.AspNet.Identity
public abstract class TotpSecurityStampBasedTokenProvider : IUserTokenProvider
where TUser : class
{
- ///
- /// Gets the name of the token provider.
- ///
- /// The name of the token provider.
- public abstract string Name { get; }
-
///
/// Generates a token for the specified and , as an asynchronous operation.
///
diff --git a/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs b/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs
index 9f6f3a5a77..5430a94c83 100644
--- a/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs
+++ b/src/Microsoft.AspNet.Identity/UserClaimsPrincipalFactory.cs
@@ -38,13 +38,13 @@ namespace Microsoft.AspNet.Identity
{
throw new ArgumentNullException(nameof(roleManager));
}
- if (optionsAccessor == null || optionsAccessor.Options == null)
+ if (optionsAccessor == null || optionsAccessor.Value == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}
UserManager = userManager;
RoleManager = roleManager;
- Options = optionsAccessor.Options;
+ Options = optionsAccessor.Value;
}
///
@@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Identity
}
var userId = await UserManager.GetUserIdAsync(user);
var userName = await UserManager.GetUserNameAsync(user);
- var id = new ClaimsIdentity(IdentityOptions.ApplicationCookieAuthenticationType,
+ var id = new ClaimsIdentity(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme,
Options.ClaimsIdentity.UserNameClaimType,
Options.ClaimsIdentity.RoleClaimType);
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
diff --git a/src/Microsoft.AspNet.Identity/UserManager.cs b/src/Microsoft.AspNet.Identity/UserManager.cs
index a8fcbe9a70..fae4cc5edf 100644
--- a/src/Microsoft.AspNet.Identity/UserManager.cs
+++ b/src/Microsoft.AspNet.Identity/UserManager.cs
@@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
+using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
@@ -51,7 +52,7 @@ namespace Microsoft.AspNet.Identity
IEnumerable> passwordValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
- IEnumerable> tokenProviders,
+ IServiceProvider services,
ILogger> logger,
IHttpContextAccessor contextAccessor)
{
@@ -60,7 +61,7 @@ namespace Microsoft.AspNet.Identity
throw new ArgumentNullException(nameof(store));
}
Store = store;
- Options = optionsAccessor?.Options ?? new IdentityOptions();
+ Options = optionsAccessor?.Value ?? new IdentityOptions();
_context = contextAccessor?.HttpContext;
PasswordHasher = passwordHasher;
KeyNormalizer = keyNormalizer;
@@ -82,11 +83,15 @@ namespace Microsoft.AspNet.Identity
}
}
- if (tokenProviders != null)
+ if (services != null)
{
- foreach (var tokenProvider in tokenProviders)
+ foreach (var providerName in Options.Tokens.ProviderMap.Keys)
{
- RegisterTokenProvider(tokenProvider);
+ var provider = services.GetRequiredService(Options.Tokens.ProviderMap[providerName].ProviderType) as IUserTokenProvider;
+ if (provider != null)
+ {
+ RegisterTokenProvider(providerName, provider);
+ }
}
}
}
@@ -715,7 +720,7 @@ namespace Microsoft.AspNet.Identity
public virtual Task GeneratePasswordResetTokenAsync(TUser user)
{
ThrowIfDisposed();
- return GenerateUserTokenAsync(user, Options.PasswordResetTokenProvider, "ResetPassword");
+ return GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword");
}
///
@@ -738,7 +743,7 @@ namespace Microsoft.AspNet.Identity
}
// Make sure the token is valid and the stamp matches
- if (!await VerifyUserTokenAsync(user, Options.PasswordResetTokenProvider, "ResetPassword", token))
+ if (!await VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword", token))
{
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
}
@@ -1260,7 +1265,7 @@ namespace Microsoft.AspNet.Identity
public virtual Task GenerateEmailConfirmationTokenAsync(TUser user)
{
ThrowIfDisposed();
- return GenerateUserTokenAsync(user, Options.EmailConfirmationTokenProvider, "EmailConfirmation");
+ return GenerateUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation");
}
///
@@ -1281,7 +1286,7 @@ namespace Microsoft.AspNet.Identity
throw new ArgumentNullException("user");
}
- if (!await VerifyUserTokenAsync(user, Options.EmailConfirmationTokenProvider, "EmailConfirmation", token))
+ if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation", token))
{
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
}
@@ -1319,7 +1324,7 @@ namespace Microsoft.AspNet.Identity
public virtual Task GenerateChangeEmailTokenAsync(TUser user, string newEmail)
{
ThrowIfDisposed();
- return GenerateUserTokenAsync(user, Options.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail));
+ return GenerateUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail));
}
///
@@ -1341,7 +1346,7 @@ namespace Microsoft.AspNet.Identity
}
// Make sure the token is valid and the stamp matches
- if (!await VerifyUserTokenAsync(user, Options.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail), token))
+ if (!await VerifyUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail), token))
{
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
}
@@ -1556,15 +1561,16 @@ namespace Microsoft.AspNet.Identity
///
/// Registers a token provider.
///
+ /// The name of the provider to register.
/// The provider to register.
- public virtual void RegisterTokenProvider(IUserTokenProvider provider)
+ public virtual void RegisterTokenProvider(string providerName, IUserTokenProvider provider)
{
ThrowIfDisposed();
if (provider == null)
{
throw new ArgumentNullException("provider");
}
- _tokenProviders[provider.Name] = provider;
+ _tokenProviders[providerName] = provider;
}
///
diff --git a/src/Microsoft.AspNet.Identity/UserOptions.cs b/src/Microsoft.AspNet.Identity/UserOptions.cs
index 8be8db924f..df1ea2aeaa 100644
--- a/src/Microsoft.AspNet.Identity/UserOptions.cs
+++ b/src/Microsoft.AspNet.Identity/UserOptions.cs
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-using System;
-
namespace Microsoft.AspNet.Identity
{
///
diff --git a/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test.xproj b/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test.xproj
index 3914283809..e469aa1435 100644
--- a/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test.xproj
+++ b/test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test/Microsoft.AspNet.Identity.EntityFramework.InMemory.Test.xproj
@@ -13,5 +13,8 @@
2.0
+
+
+
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs
index 58ab902a35..2ab22326c3 100644
--- a/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs
+++ b/test/Microsoft.AspNet.Identity.InMemory.Test/FunctionalTest.cs
@@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Identity.InMemory
public async Task CanChangePasswordOptions()
{
var clock = new TestClock();
- var server = CreateServer(services => services.ConfigureIdentity(options =>
+ var server = CreateServer(services => services.Configure(options =>
{
options.Password.RequireUppercase = false;
options.Password.RequireNonLetterOrDigit = false;
@@ -53,11 +53,11 @@ namespace Microsoft.AspNet.Identity.InMemory
public async Task CanCreateMeLoginAndCookieStopsWorkingAfterExpiration()
{
var clock = new TestClock();
- var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
+ var server = CreateServer(services => services.Configure(options =>
{
- appCookieOptions.SystemClock = clock;
- appCookieOptions.ExpireTimeSpan = TimeSpan.FromMinutes(10);
- appCookieOptions.SlidingExpiration = false;
+ options.Cookies.ApplicationCookie.SystemClock = clock;
+ options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(10);
+ options.Cookies.ApplicationCookie.SlidingExpiration = false;
}));
var transaction1 = await SendAsync(server, "http://example.com/createMe");
@@ -92,9 +92,9 @@ namespace Microsoft.AspNet.Identity.InMemory
public async Task CanCreateMeLoginAndSecurityStampExtendsExpiration(bool rememberMe)
{
var clock = new TestClock();
- var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
+ var server = CreateServer(services => services.Configure(options =>
{
- appCookieOptions.SystemClock = clock;
+ options.Cookies.ApplicationCookie.SystemClock = clock;
}));
var transaction1 = await SendAsync(server, "http://example.com/createMe");
@@ -148,7 +148,7 @@ namespace Microsoft.AspNet.Identity.InMemory
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
string setCookie = transaction2.SetCookie;
- setCookie.ShouldContain(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme + "=");
+ setCookie.ShouldContain(new IdentityCookieOptions().TwoFactorRememberMeCookieAuthenticationScheme + "=");
setCookie.ShouldContain("; expires=");
var transaction3 = await SendAsync(server, "http://example.com/isTwoFactorRememebered", transaction2.CookieNameValue);
diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs
index 94844ebc93..433998ae6d 100644
--- a/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs
+++ b/test/Microsoft.AspNet.Identity.InMemory.Test/HttpSignInTest.cs
@@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
var context = new Mock();
var auth = new Mock();
context.Setup(c => c.Authentication).Returns(auth.Object).Verifiable();
- auth.Setup(a => a.SignInAsync(IdentityOptions.ApplicationCookieAuthenticationScheme,
+ auth.Setup(a => a.SignInAsync(new IdentityCookieOptions().ApplicationCookieAuthenticationScheme,
It.IsAny(),
It.IsAny())).Returns(Task.FromResult(0)).Verifiable();
// REVIEW: is persistant mocking broken
diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/Microsoft.AspNet.Identity.InMemory.Test.xproj b/test/Microsoft.AspNet.Identity.InMemory.Test/Microsoft.AspNet.Identity.InMemory.Test.xproj
index 2d1b8e9294..7b09944843 100644
--- a/test/Microsoft.AspNet.Identity.InMemory.Test/Microsoft.AspNet.Identity.InMemory.Test.xproj
+++ b/test/Microsoft.AspNet.Identity.InMemory.Test/Microsoft.AspNet.Identity.InMemory.Test.xproj
@@ -13,5 +13,8 @@
2.0
+
+
+
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Identity.Test/IdentityBuilderTest.cs b/test/Microsoft.AspNet.Identity.Test/IdentityBuilderTest.cs
index 7724233c86..29394fc696 100644
--- a/test/Microsoft.AspNet.Identity.Test/IdentityBuilderTest.cs
+++ b/test/Microsoft.AspNet.Identity.Test/IdentityBuilderTest.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
+using Microsoft.Framework.OptionsModel;
using Xunit;
namespace Microsoft.AspNet.Identity.Test
@@ -105,10 +106,30 @@ namespace Microsoft.AspNet.Identity.Test
services.AddIdentity().AddDefaultTokenProviders();
var provider = services.BuildServiceProvider();
- var tokenProviders = provider.GetRequiredService>>();
+ var tokenProviders = provider.GetRequiredService>().Value.Tokens.ProviderMap.Values;
Assert.Equal(3, tokenProviders.Count());
}
+ [Fact]
+ public void AddManagerWithWrongTypesThrows()
+ {
+ var services = new ServiceCollection();
+ var builder = services.AddIdentity();
+ Assert.Throws(() => builder.AddUserManager>());
+ Assert.Throws(() => builder.AddRoleManager>());
+ Assert.Throws(() => builder.AddUserManager