Fix cookie authentication type regression

This commit is contained in:
Hao Kung 2015-09-03 15:43:56 -07:00
parent a506979db5
commit f8733aa103
4 changed files with 12 additions and 15 deletions

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Authentication;
using Microsoft.AspNet.Identity;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection.Extensions;
namespace Microsoft.Framework.DependencyInjection
@ -45,7 +43,11 @@ namespace Microsoft.Framework.DependencyInjection
{
// Services used by identity
services.AddOptions();
services.AddAuthentication();
services.AddAuthentication(options =>
{
// This is the Default value for ExternalCookieAuthenticationScheme
options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme;
});
// Identity services
services.TryAddSingleton<IdentityMarkerService>();
@ -64,13 +66,8 @@ namespace Microsoft.Framework.DependencyInjection
if (setupAction != null)
{
services.Configure<IdentityOptions>(setupAction);
services.Configure(setupAction);
}
services.Configure<SharedAuthenticationOptions>(options =>
{
// This is the Default value for ExternalCookieAuthenticationScheme
options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme;
});
return new IdentityBuilder(typeof(TUser), typeof(TRole), services);
}

View File

@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Identity
}
var userId = await UserManager.GetUserIdAsync(user);
var userName = await UserManager.GetUserNameAsync(user);
var id = new ClaimsIdentity(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme,
var id = new ClaimsIdentity(Options.Cookies.ApplicationCookieAuthenticationScheme,
Options.ClaimsIdentity.UserNameClaimType,
Options.ClaimsIdentity.RoleClaimType);
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));

View File

@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Identity.InMemory
var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber");
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
string setCookie = transaction2.SetCookie;
var setCookie = transaction2.SetCookie;
setCookie.ShouldContain(new IdentityCookieOptions().TwoFactorRememberMeCookieAuthenticationScheme + "=");
setCookie.ShouldContain("; expires=");
@ -170,9 +170,9 @@ namespace Microsoft.AspNet.Identity.InMemory
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("Cookie", cookie);
HttpResponseMessage response2 = await server.CreateClient().SendAsync(request);
string text = await response2.Content.ReadAsStringAsync();
XElement me = XElement.Parse(text);
var response2 = await server.CreateClient().SendAsync(request);
var text = await response2.Content.ReadAsStringAsync();
var me = XElement.Parse(text);
return me;
}

View File

@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Identity.Test
var manager = userManager.Object;
Assert.NotNull(identity);
Assert.Equal(1, principal.Identities.Count());
Assert.Equal(identityOptions.Cookies.TwoFactorRememberMeCookieAuthenticationScheme, identity.AuthenticationType);
Assert.Equal(identityOptions.Cookies.ApplicationCookieAuthenticationScheme, identity.AuthenticationType);
var claims = identity.Claims.ToList();
Assert.NotNull(claims);
Assert.True(