Remove redundant setters for CookieAuthSchemes

This commit is contained in:
Hao Kung 2016-02-12 10:57:52 -08:00
parent 57307ef2b7
commit 06f4c306b7
3 changed files with 21 additions and 17 deletions

View File

@ -48,7 +48,6 @@ namespace IdentitySample
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>(options => {
options.Cookies.ApplicationCookieAuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.DataProtectionProvider = new DataProtectionProvider(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
options.Cookies.ApplicationCookie.CookieName = "Interop";

View File

@ -13,12 +13,17 @@ namespace Microsoft.AspNetCore.Identity
/// </summary>
public class IdentityCookieOptions
{
private static readonly string DefaultApplicationScheme = typeof(IdentityCookieOptions).Namespace + ".Application";
private static readonly string DefaultExternalScheme = typeof(IdentityCookieOptions).Namespace + ".External";
private static readonly string DefaultTwoFactorRememberMeScheme = typeof(IdentityCookieOptions).Namespace + ".TwoFactorRememberMe";
private static readonly string DefaultTwoFactorUserIdScheme = typeof(IdentityCookieOptions).Namespace + ".TwoFactorUserId";
public IdentityCookieOptions()
{
// Configure all of the cookie middlewares
ApplicationCookie = new CookieAuthenticationOptions
{
AuthenticationScheme = ApplicationCookieAuthenticationScheme,
AuthenticationScheme = DefaultApplicationScheme,
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = new PathString("/Account/Login"),
@ -30,21 +35,21 @@ namespace Microsoft.AspNetCore.Identity
ExternalCookie = new CookieAuthenticationOptions
{
AuthenticationScheme = ExternalCookieAuthenticationScheme,
CookieName = ExternalCookieAuthenticationScheme,
AuthenticationScheme = DefaultExternalScheme,
CookieName = DefaultExternalScheme,
ExpireTimeSpan = TimeSpan.FromMinutes(5)
};
TwoFactorRememberMeCookie = new CookieAuthenticationOptions
{
AuthenticationScheme = TwoFactorRememberMeCookieAuthenticationScheme,
CookieName = TwoFactorRememberMeCookieAuthenticationScheme
AuthenticationScheme = DefaultTwoFactorRememberMeScheme,
CookieName = DefaultTwoFactorRememberMeScheme
};
TwoFactorUserIdCookie = new CookieAuthenticationOptions
{
AuthenticationScheme = TwoFactorUserIdCookieAuthenticationScheme,
CookieName = TwoFactorUserIdCookieAuthenticationScheme,
AuthenticationScheme = DefaultTwoFactorUserIdScheme,
CookieName = DefaultTwoFactorUserIdScheme,
ExpireTimeSpan = TimeSpan.FromMinutes(5)
};
@ -56,27 +61,27 @@ namespace Microsoft.AspNetCore.Identity
public CookieAuthenticationOptions TwoFactorUserIdCookie { get; set; }
/// <summary>
/// Gets or sets the scheme used to identify application authentication cookies.
/// Gets the scheme used to identify application authentication cookies.
/// </summary>
/// <value>The scheme used to identify application authentication cookies.</value>
public string ApplicationCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".Application";
public string ApplicationCookieAuthenticationScheme => ApplicationCookie?.AuthenticationScheme;
/// <summary>
/// Gets or sets the scheme used to identify external authentication cookies.
/// Gets the scheme used to identify external authentication cookies.
/// </summary>
/// <value>The scheme used to identify external authentication cookies.</value>
public string ExternalCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".External";
public string ExternalCookieAuthenticationScheme => ExternalCookie?.AuthenticationScheme;
/// <summary>
/// Gets or sets the scheme used to identify Two Factor authentication cookies for round tripping user identities.
/// Gets the scheme used to identify Two Factor authentication cookies for round tripping user identities.
/// </summary>
/// <value>The scheme used to identify user identity 2fa authentication cookies.</value>
public string TwoFactorUserIdCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".TwoFactorUserId";
public string TwoFactorUserIdCookieAuthenticationScheme => TwoFactorUserIdCookie?.AuthenticationScheme;
/// <summary>
/// Gets or sets the scheme used to identify Two Factor authentication cookies for saving the Remember Me state.
/// Gets the scheme used to identify Two Factor authentication cookies for saving the Remember Me state.
/// </summary>
/// <value>The scheme used to identify remember me application authentication cookies.</value>
public string TwoFactorRememberMeCookieAuthenticationScheme { get; set; } = typeof(IdentityCookieOptions).Namespace + ".TwoFactorRememberMe";
public string TwoFactorRememberMeCookieAuthenticationScheme => TwoFactorRememberMeCookie?.AuthenticationScheme;
}
}

View File

@ -503,7 +503,7 @@ namespace Microsoft.AspNetCore.Identity.Test
{
// Setup
var manager = MockHelpers.TestUserManager<TestUser>();
manager.Options.Cookies.ApplicationCookieAuthenticationScheme = authenticationScheme;
manager.Options.Cookies.ApplicationCookie.AuthenticationScheme = authenticationScheme;
var context = new Mock<HttpContext>();
var auth = new Mock<AuthenticationManager>();
context.Setup(c => c.Authentication).Returns(auth.Object).Verifiable();