Fix cookie authentication type regression
This commit is contained in:
parent
a506979db5
commit
f8733aa103
|
|
@ -2,9 +2,7 @@
|
||||||
// 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;
|
using System;
|
||||||
using Microsoft.AspNet.Authentication;
|
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
using Microsoft.Framework.Configuration;
|
|
||||||
using Microsoft.Framework.DependencyInjection.Extensions;
|
using Microsoft.Framework.DependencyInjection.Extensions;
|
||||||
|
|
||||||
namespace Microsoft.Framework.DependencyInjection
|
namespace Microsoft.Framework.DependencyInjection
|
||||||
|
|
@ -45,7 +43,11 @@ namespace Microsoft.Framework.DependencyInjection
|
||||||
{
|
{
|
||||||
// Services used by identity
|
// Services used by identity
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
services.AddAuthentication();
|
services.AddAuthentication(options =>
|
||||||
|
{
|
||||||
|
// This is the Default value for ExternalCookieAuthenticationScheme
|
||||||
|
options.SignInScheme = new IdentityCookieOptions().ExternalCookieAuthenticationScheme;
|
||||||
|
});
|
||||||
|
|
||||||
// Identity services
|
// Identity services
|
||||||
services.TryAddSingleton<IdentityMarkerService>();
|
services.TryAddSingleton<IdentityMarkerService>();
|
||||||
|
|
@ -64,13 +66,8 @@ namespace Microsoft.Framework.DependencyInjection
|
||||||
|
|
||||||
if (setupAction != null)
|
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);
|
return new IdentityBuilder(typeof(TUser), typeof(TRole), services);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
var userId = await UserManager.GetUserIdAsync(user);
|
var userId = await UserManager.GetUserIdAsync(user);
|
||||||
var userName = await UserManager.GetUserNameAsync(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.UserNameClaimType,
|
||||||
Options.ClaimsIdentity.RoleClaimType);
|
Options.ClaimsIdentity.RoleClaimType);
|
||||||
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
|
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber");
|
var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber");
|
||||||
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
|
|
||||||
string setCookie = transaction2.SetCookie;
|
var setCookie = transaction2.SetCookie;
|
||||||
setCookie.ShouldContain(new IdentityCookieOptions().TwoFactorRememberMeCookieAuthenticationScheme + "=");
|
setCookie.ShouldContain(new IdentityCookieOptions().TwoFactorRememberMeCookieAuthenticationScheme + "=");
|
||||||
setCookie.ShouldContain("; expires=");
|
setCookie.ShouldContain("; expires=");
|
||||||
|
|
||||||
|
|
@ -170,9 +170,9 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
request.Headers.Add("Cookie", cookie);
|
request.Headers.Add("Cookie", cookie);
|
||||||
|
|
||||||
HttpResponseMessage response2 = await server.CreateClient().SendAsync(request);
|
var response2 = await server.CreateClient().SendAsync(request);
|
||||||
string text = await response2.Content.ReadAsStringAsync();
|
var text = await response2.Content.ReadAsStringAsync();
|
||||||
XElement me = XElement.Parse(text);
|
var me = XElement.Parse(text);
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
var manager = userManager.Object;
|
var manager = userManager.Object;
|
||||||
Assert.NotNull(identity);
|
Assert.NotNull(identity);
|
||||||
Assert.Equal(1, principal.Identities.Count());
|
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();
|
var claims = identity.Claims.ToList();
|
||||||
Assert.NotNull(claims);
|
Assert.NotNull(claims);
|
||||||
Assert.True(
|
Assert.True(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue