diff --git a/src/Microsoft.AspNet.Identity.Security/DefaultAuthenticationTypes.cs b/src/Microsoft.AspNet.Identity.Security/DefaultAuthenticationTypes.cs new file mode 100644 index 0000000000..8d50b752d4 --- /dev/null +++ b/src/Microsoft.AspNet.Identity.Security/DefaultAuthenticationTypes.cs @@ -0,0 +1,7 @@ +namespace Microsoft.AspNet.Identity.Security +{ + public static class DefaultAuthenticationTypes + { + public const string ApplicationCookie = "Microsoft.Aspnet.Identity.Security.Application"; + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity.Security/SignInManager.cs b/src/Microsoft.AspNet.Identity.Security/SignInManager.cs index 2cd1d9fadb..49c8bb27eb 100644 --- a/src/Microsoft.AspNet.Identity.Security/SignInManager.cs +++ b/src/Microsoft.AspNet.Identity.Security/SignInManager.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Identity.Security private string _authType; public string AuthenticationType { - get { return _authType ?? "Microsoft.AspNet.Identity"; } + get { return _authType ?? DefaultAuthenticationTypes.ApplicationCookie; } set { _authType = value; } } @@ -39,6 +39,15 @@ namespace Microsoft.AspNet.Identity.Security Context.Response.SignIn(userIdentity, new AuthenticationProperties { IsPersistent = isPersistent }); } + public virtual void SignOut() + { + if (Context == null) + { + return; + } + Context.Response.SignOut(AuthenticationType); + } + //public virtual async Task SendTwoFactorCode(string provider) //{ // var userId = await GetVerifiedUserId(); diff --git a/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs b/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs index aa1eb7e0fe..fa2ec6cd54 100644 --- a/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs +++ b/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs @@ -1600,22 +1600,6 @@ namespace Microsoft.AspNet.Identity.Entity.Test Assert.False(await manager.VerifyTwoFactorTokenAsync(user, factorId, "bogus")); } - private class DataStoreConfig : ContextConfiguration - { - private readonly DataStore _store; - - public DataStoreConfig(DataStore store) - { - _store = store; - } - - public override DataStore DataStore - { - get { return _store; } - } - - } - public class TestMessageService : IIdentityMessageService { public IdentityMessage Message { get; set; } diff --git a/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs b/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs index e210e8e377..7fbdfc3451 100644 --- a/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs +++ b/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Identity.Security.Test manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(false).Verifiable(); manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); manager.Setup(m => m.CheckPasswordAsync(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable(); - manager.Setup(m => m.CreateIdentityAsync(user, "Microsoft.AspNet.Identity", CancellationToken.None)).ReturnsAsync(new ClaimsIdentity("Microsoft.AspNet.Identity")).Verifiable(); + manager.Setup(m => m.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie, CancellationToken.None)).ReturnsAsync(new ClaimsIdentity("Microsoft.AspNet.Identity")).Verifiable(); var context = new Mock(); var response = new Mock(); context.Setup(c => c.Response).Returns(response.Object).Verifiable(); @@ -80,6 +80,26 @@ namespace Microsoft.AspNet.Identity.Security.Test manager.VerifyAll(); } + [Theory] + [InlineData(DefaultAuthenticationTypes.ApplicationCookie)] + [InlineData("Foo")] + public void SignOutCallsContextResponseSignOut(string authenticationType) + { + // Setup + var context = new Mock(); + var response = new Mock(); + context.Setup(c => c.Response).Returns(response.Object).Verifiable(); + response.Setup(r => r.SignOut(authenticationType)).Verifiable(); + var helper = new SignInManager { Context = context.Object, AuthenticationType = authenticationType }; + + // Act + helper.SignOut(); + + // Assert + context.VerifyAll(); + response.VerifyAll(); + } + [Fact] public async Task PasswordSignInFailsWithWrongPassword() { @@ -139,6 +159,16 @@ namespace Microsoft.AspNet.Identity.Security.Test await helper.SignInAsync(null, false, false); } + [Fact] + public void SignOutWithNoContextDoesNotBlowUp() + { + // Setup + var helper = new SignInManager(); + + // Act + helper.SignOut(); + } + [Fact] public async Task CreateUserIdentityReturnsNullNoUserManager() {