diff --git a/Security.sln b/Security.sln index 77ed55284..28ecb032e 100644 --- a/Security.sln +++ b/Security.sln @@ -50,11 +50,11 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.CookiePoli EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Authentication.JwtBearer", "src\Microsoft.AspNet.Authentication.JwtBearer\Microsoft.AspNet.Authentication.JwtBearer.xproj", "{2755BFE5-7421-4A31-A644-F817DF5CAA98}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Owin.Security.Cookies.Interop", "src\Microsoft.Owin.Security.Cookies.Interop\Microsoft.Owin.Security.Cookies.Interop.xproj", "{21A56E78-31DE-4868-9778-7E4DBE2A4E35}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "JwtBearerSample", "samples\JwtBearerSample\JwtBearerSample.xproj", "{D399B84F-591B-4E98-92BA-B0F63E7B6957}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Owin.Security.Cookies.Interop.Test", "test\Microsoft.Owin.Security.Cookies.Interop.Test\Microsoft.Owin.Security.Cookies.Interop.Test.xproj", "{73E8E654-A2AC-4848-95F3-EB55512F6C39}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Owin.Security.Interop", "src\Microsoft.Owin.Security.Interop\Microsoft.Owin.Security.Interop.xproj", "{A7922DD8-09F1-43E4-938B-CC523EA08898}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "JwtBearerSample", "samples\JwtBearerSample\JwtBearerSample.xproj", "{D399B84F-591B-4E98-92BA-B0F63E7B6957}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Owin.Security.Interop.Test", "test\Microsoft.Owin.Security.Interop.Test\Microsoft.Owin.Security.Interop.Test.xproj", "{A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -276,30 +276,6 @@ Global {2755BFE5-7421-4A31-A644-F817DF5CAA98}.Release|Mixed Platforms.Build.0 = Release|Any CPU {2755BFE5-7421-4A31-A644-F817DF5CAA98}.Release|x86.ActiveCfg = Release|Any CPU {2755BFE5-7421-4A31-A644-F817DF5CAA98}.Release|x86.Build.0 = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|Any CPU.Build.0 = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|x86.ActiveCfg = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Debug|x86.Build.0 = Debug|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|Any CPU.ActiveCfg = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|Any CPU.Build.0 = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|x86.ActiveCfg = Release|Any CPU - {21A56E78-31DE-4868-9778-7E4DBE2A4E35}.Release|x86.Build.0 = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|x86.ActiveCfg = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Debug|x86.Build.0 = Debug|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|Any CPU.Build.0 = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|x86.ActiveCfg = Release|Any CPU - {73E8E654-A2AC-4848-95F3-EB55512F6C39}.Release|x86.Build.0 = Release|Any CPU {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Debug|Any CPU.Build.0 = Debug|Any CPU {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -312,6 +288,30 @@ Global {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Release|Mixed Platforms.Build.0 = Release|Any CPU {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Release|x86.ActiveCfg = Release|Any CPU {D399B84F-591B-4E98-92BA-B0F63E7B6957}.Release|x86.Build.0 = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|x86.ActiveCfg = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Debug|x86.Build.0 = Debug|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|Any CPU.Build.0 = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|x86.ActiveCfg = Release|Any CPU + {A7922DD8-09F1-43E4-938B-CC523EA08898}.Release|x86.Build.0 = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|x86.ActiveCfg = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Debug|x86.Build.0 = Debug|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|Any CPU.Build.0 = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|x86.ActiveCfg = Release|Any CPU + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -335,8 +335,8 @@ Global {86183DC3-02A8-4A68-8B60-71ECEC066E79} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} {1790E052-646F-4529-B90E-6FEA95520D69} = {7BF11F3A-60B6-4796-B504-579C67FFBA34} {2755BFE5-7421-4A31-A644-F817DF5CAA98} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} - {21A56E78-31DE-4868-9778-7E4DBE2A4E35} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} - {73E8E654-A2AC-4848-95F3-EB55512F6C39} = {7BF11F3A-60B6-4796-B504-579C67FFBA34} {D399B84F-591B-4E98-92BA-B0F63E7B6957} = {F8C0AA27-F3FB-4286-8E4C-47EF86B539FF} + {A7922DD8-09F1-43E4-938B-CC523EA08898} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} + {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24} = {7BF11F3A-60B6-4796-B504-579C67FFBA34} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs b/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs index a252b138c..63f97cc9e 100644 --- a/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/TicketDataFormat.cs @@ -7,7 +7,8 @@ namespace Microsoft.AspNet.Authentication { public class TicketDataFormat : SecureDataFormat { - public TicketDataFormat(IDataProtector protector) : base(new TicketSerializer(), protector) + public TicketDataFormat(IDataProtector protector) + : base(TicketSerializer.Default, protector) { } } diff --git a/src/Microsoft.AspNet.Authentication/DataHandler/TicketSerializer.cs b/src/Microsoft.AspNet.Authentication/DataHandler/TicketSerializer.cs index 8fae5f923..36b269592 100644 --- a/src/Microsoft.AspNet.Authentication/DataHandler/TicketSerializer.cs +++ b/src/Microsoft.AspNet.Authentication/DataHandler/TicketSerializer.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication { - // This MUST be kept in sync with Microsoft.Owin.Security.Cookies.AspNetTicketSerializer + // This MUST be kept in sync with Microsoft.Owin.Security.Interop.AspNetTicketSerializer public class TicketSerializer : IDataSerializer { private const string DefaultStringPlaceholder = "\0"; diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/CookieAuthenticationExtensions.cs b/src/Microsoft.Owin.Security.Cookies.Interop/CookieAuthenticationExtensions.cs deleted file mode 100644 index 3bbe74aad..000000000 --- a/src/Microsoft.Owin.Security.Cookies.Interop/CookieAuthenticationExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNet.DataProtection; -using Microsoft.Owin.Security.Cookies; -using Microsoft.Owin.Security.Cookies.Interop; - -namespace Owin -{ - public static class CookieAuthenticationExtensions - { - public static IAppBuilder UseCookieAuthentication( - this IAppBuilder app, - CookieAuthenticationOptions options, - DataProtectionProvider dataProtectionProvider, - PipelineStage stage = PipelineStage.Authenticate) - { - var dataProtector = dataProtectionProvider.CreateProtector( - "Microsoft.AspNet.Authentication.Cookies.CookieAuthenticationMiddleware", // full name of the ASP.NET 5 type - options.AuthenticationType, "v2"); - options.TicketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector)); - - return app.UseCookieAuthentication(options, stage); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/DefaultCompatibilityConstants.cs b/src/Microsoft.Owin.Security.Cookies.Interop/DefaultCompatibilityConstants.cs deleted file mode 100644 index b403033e3..000000000 --- a/src/Microsoft.Owin.Security.Cookies.Interop/DefaultCompatibilityConstants.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Identity -{ - /// - /// Helpful constants for working with the authentication cookie compatibility shim. - /// - public static class DefaultCompatibilityConstants - { - /// - /// The default authentication type for application authentication cookies. - /// - public const string ApplicationCookieAuthenticationType = "Microsoft.AspNet.Identity.Application.AuthType"; - - /// - /// The default cookie name for application authentication cookies. - /// Used by . - /// - public const string CookieName = ".AspNet.Microsoft.AspNet.Identity.Application"; - } -} \ No newline at end of file diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/Properties/AssemblyInfo.cs b/src/Microsoft.Owin.Security.Cookies.Interop/Properties/AssemblyInfo.cs deleted file mode 100644 index b2437d9ad..000000000 --- a/src/Microsoft.Owin.Security.Cookies.Interop/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -// 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.Reflection; -using System.Resources; - -[assembly: AssemblyMetadata("Serviceable", "True")] -[assembly: NeutralResourcesLanguage("en-us")] \ No newline at end of file diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/project.json b/src/Microsoft.Owin.Security.Cookies.Interop/project.json deleted file mode 100644 index 30053b01e..000000000 --- a/src/Microsoft.Owin.Security.Cookies.Interop/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "1.0.0-*", - "compilationOptions": { - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" - }, - "description": "A compatibility layer for sharing authentication tickets between Microsoft.Owin.Security.Cookies and Microsoft.AspNet.Authentication.Cookies.", - "dependencies": { - }, - "frameworks": { - "net451": { - "dependencies": { - "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", - "Microsoft.Owin.Security.Cookies": "3.0.1" - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketDataFormat.cs b/src/Microsoft.Owin.Security.Interop/AspNetTicketDataFormat.cs similarity index 78% rename from src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketDataFormat.cs rename to src/Microsoft.Owin.Security.Interop/AspNetTicketDataFormat.cs index 48ded3309..f1a07c5bf 100644 --- a/src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketDataFormat.cs +++ b/src/Microsoft.Owin.Security.Interop/AspNetTicketDataFormat.cs @@ -5,12 +5,12 @@ using Microsoft.Owin.Security.DataHandler.Encoder; using Microsoft.Owin.Security.DataProtection; -namespace Microsoft.Owin.Security.Cookies.Interop +namespace Microsoft.Owin.Security.Interop { public class AspNetTicketDataFormat : SecureDataFormat { public AspNetTicketDataFormat(IDataProtector protector) - : base(new AspNetTicketSerializer(), protector, TextEncodings.Base64Url) + : base(AspNetTicketSerializer.Default, protector, TextEncodings.Base64Url) { } } diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketSerializer.cs b/src/Microsoft.Owin.Security.Interop/AspNetTicketSerializer.cs similarity index 98% rename from src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketSerializer.cs rename to src/Microsoft.Owin.Security.Interop/AspNetTicketSerializer.cs index 8727f7c46..2bfc44fde 100644 --- a/src/Microsoft.Owin.Security.Cookies.Interop/AspNetTicketSerializer.cs +++ b/src/Microsoft.Owin.Security.Interop/AspNetTicketSerializer.cs @@ -7,7 +7,7 @@ using System.Security.Claims; using Microsoft.Owin.Security.DataHandler.Serializer; -namespace Microsoft.Owin.Security.Cookies.Interop +namespace Microsoft.Owin.Security.Interop { // This MUST be kept in sync with Microsoft.AspNet.Authentication.DataHandler.TicketSerializer public class AspNetTicketSerializer : IDataSerializer @@ -15,7 +15,7 @@ public class AspNetTicketSerializer : IDataSerializer private const string DefaultStringPlaceholder = "\0"; private const int FormatVersion = 5; - public static TicketSerializer Default { get; } = new TicketSerializer(); + public static AspNetTicketSerializer Default { get; } = new AspNetTicketSerializer(); public virtual byte[] Serialize(AuthenticationTicket ticket) { diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/DataProtectorShim.cs b/src/Microsoft.Owin.Security.Interop/DataProtectorShim.cs similarity index 84% rename from src/Microsoft.Owin.Security.Cookies.Interop/DataProtectorShim.cs rename to src/Microsoft.Owin.Security.Interop/DataProtectorShim.cs index 0dab249ae..9dc7eedda 100644 --- a/src/Microsoft.Owin.Security.Cookies.Interop/DataProtectorShim.cs +++ b/src/Microsoft.Owin.Security.Interop/DataProtectorShim.cs @@ -3,13 +3,13 @@ using Microsoft.AspNet.DataProtection; -namespace Microsoft.Owin.Security.Cookies.Interop +namespace Microsoft.Owin.Security.Interop { /// /// Converts an to an /// . /// - internal sealed class DataProtectorShim : Microsoft.Owin.Security.DataProtection.IDataProtector + public sealed class DataProtectorShim : Microsoft.Owin.Security.DataProtection.IDataProtector { private readonly IDataProtector _protector; diff --git a/src/Microsoft.Owin.Security.Cookies.Interop/Microsoft.Owin.Security.Cookies.Interop.xproj b/src/Microsoft.Owin.Security.Interop/Microsoft.Owin.Security.Interop.xproj similarity index 70% rename from src/Microsoft.Owin.Security.Cookies.Interop/Microsoft.Owin.Security.Cookies.Interop.xproj rename to src/Microsoft.Owin.Security.Interop/Microsoft.Owin.Security.Interop.xproj index fd666b061..bb58ad712 100644 --- a/src/Microsoft.Owin.Security.Cookies.Interop/Microsoft.Owin.Security.Cookies.Interop.xproj +++ b/src/Microsoft.Owin.Security.Interop/Microsoft.Owin.Security.Interop.xproj @@ -4,16 +4,17 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + - 21a56e78-31de-4868-9778-7e4dbe2a4e35 - Microsoft.Owin.Security.Cookies.Shareable - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + a7922dd8-09f1-43e4-938b-cc523ea08898 + Microsoft.Owin.Security.Interop + ..\artifacts\obj\$(MSBuildProjectName) + ..\artifacts\bin\$(MSBuildProjectName)\ 2.0 - \ No newline at end of file + diff --git a/src/Microsoft.Owin.Security.Interop/Properties/AssemblyInfo.cs b/src/Microsoft.Owin.Security.Interop/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..4f0007e9c --- /dev/null +++ b/src/Microsoft.Owin.Security.Interop/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.Owin.Security.Interop")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Microsoft.Owin.Security.Interop")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a7922dd8-09f1-43e4-938b-cc523ea08898")] diff --git a/src/Microsoft.Owin.Security.Interop/project.json b/src/Microsoft.Owin.Security.Interop/project.json new file mode 100644 index 000000000..b3c352a87 --- /dev/null +++ b/src/Microsoft.Owin.Security.Interop/project.json @@ -0,0 +1,15 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "warningsAsErrors": true, + "keyFile": "../../tools/Key.snk" + }, + "description": "A compatibility layer for sharing authentication tickets between Microsoft.Owin.Security and Microsoft.AspNet.Authentication.", + "dependencies": { + "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", + "Microsoft.Owin.Security": "3.0.1" + }, + "frameworks": { + "net451": { } + } +} \ No newline at end of file diff --git a/test/Microsoft.Owin.Security.Cookies.Interop.Test/TicketInteropTests.cs b/test/Microsoft.Owin.Security.Interop.Test/CookieInteropTests.cs similarity index 63% rename from test/Microsoft.Owin.Security.Cookies.Interop.Test/TicketInteropTests.cs rename to test/Microsoft.Owin.Security.Interop.Test/CookieInteropTests.cs index 71acba597..9ef81bc7f 100644 --- a/test/Microsoft.Owin.Security.Cookies.Interop.Test/TicketInteropTests.cs +++ b/test/Microsoft.Owin.Security.Interop.Test/CookieInteropTests.cs @@ -1,117 +1,48 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.IO; using System.Linq; using System.Net.Http; -using Microsoft.AspNet.Http; using System.Security.Claims; using System.Text; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; -using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; -using Microsoft.Owin.Security.Cookies.Interop; using Microsoft.Owin.Testing; using Owin; using Xunit; -namespace Microsoft.AspNet.CookiePolicy.Test +namespace Microsoft.Owin.Security.Interop { - public class TicketInteropTests + public class CookiesInteropTests { - [Fact] - public void NewSerializerCanReadInteropTicket() - { - var identity = new ClaimsIdentity("scheme"); - identity.AddClaim(new Claim("Test", "Value")); - - var expires = DateTime.Today; - var issued = new DateTime(1979, 11, 11); - var properties = new Owin.Security.AuthenticationProperties(); - properties.IsPersistent = true; - properties.RedirectUri = "/redirect"; - properties.Dictionary["key"] = "value"; - properties.ExpiresUtc = expires; - properties.IssuedUtc = issued; - - var interopTicket = new Owin.Security.AuthenticationTicket(identity, properties); - var interopSerializer = new AspNetTicketSerializer(); - - var bytes = interopSerializer.Serialize(interopTicket); - - var newSerializer = new TicketSerializer(); - var newTicket = newSerializer.Deserialize(bytes); - - Assert.NotNull(newTicket); - Assert.Equal(1, newTicket.Principal.Identities.Count()); - var newIdentity = newTicket.Principal.Identity as ClaimsIdentity; - Assert.NotNull(newIdentity); - Assert.Equal("scheme", newIdentity.AuthenticationType); - Assert.True(newIdentity.HasClaim(c => c.Type == "Test" && c.Value == "Value")); - Assert.NotNull(newTicket.Properties); - Assert.True(newTicket.Properties.IsPersistent); - Assert.Equal("/redirect", newTicket.Properties.RedirectUri); - Assert.Equal("value", newTicket.Properties.Items["key"]); - Assert.Equal(expires, newTicket.Properties.ExpiresUtc); - Assert.Equal(issued, newTicket.Properties.IssuedUtc); - } - - [Fact] - public void InteropSerializerCanReadNewTicket() - { - var user = new ClaimsPrincipal(); - var identity = new ClaimsIdentity("scheme"); - identity.AddClaim(new Claim("Test", "Value")); - user.AddIdentity(identity); - - var expires = DateTime.Today; - var issued = new DateTime(1979, 11, 11); - var properties = new Http.Authentication.AuthenticationProperties(); - properties.IsPersistent = true; - properties.RedirectUri = "/redirect"; - properties.Items["key"] = "value"; - properties.ExpiresUtc = expires; - properties.IssuedUtc = issued; - - var newTicket = new AuthenticationTicket(user, properties, "scheme"); - var newSerializer = new TicketSerializer(); - - var bytes = newSerializer.Serialize(newTicket); - - var interopSerializer = new AspNetTicketSerializer(); - var interopTicket = interopSerializer.Deserialize(bytes); - - Assert.NotNull(interopTicket); - var newIdentity = interopTicket.Identity; - Assert.NotNull(newIdentity); - Assert.Equal("scheme", newIdentity.AuthenticationType); - Assert.True(newIdentity.HasClaim(c => c.Type == "Test" && c.Value == "Value")); - Assert.NotNull(interopTicket.Properties); - Assert.True(interopTicket.Properties.IsPersistent); - Assert.Equal("/redirect", interopTicket.Properties.RedirectUri); - Assert.Equal("value", interopTicket.Properties.Dictionary["key"]); - Assert.Equal(expires, interopTicket.Properties.ExpiresUtc); - Assert.Equal(issued, interopTicket.Properties.IssuedUtc); - } - [Fact] public async Task AspNet5WithInteropCookieContainsIdentity() { var identity = new ClaimsIdentity("Cookies"); identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); - var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); + var dataProtection = new DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); + var dataProtector = dataProtection.CreateProtector( + "Microsoft.AspNet.Authentication.Cookies.CookieAuthenticationMiddleware", // full name of the ASP.NET 5 type + CookieAuthenticationDefaults.AuthenticationType, "v2"); + var interopServer = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; - app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); + + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + TicketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector)) + }); + app.Run(context => { context.Authentication.SignIn(identity); @@ -132,7 +63,7 @@ public async Task AspNet5WithInteropCookieContainsIdentity() }); }) .ConfigureServices(services => services.AddAuthentication()); - var newServer = new TestHost.TestServer(builder); + var newServer = new AspNet.TestHost.TestServer(builder); var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com/login"); request.Headers.Add("Cookie", transaction.SetCookie.Split(new[] { ';' }, 2).First()); @@ -149,7 +80,11 @@ public async Task InteropWithNewCookieContainsIdentity() identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); user.AddIdentity(identity); - var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); + var dataProtection = new DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); + var dataProtector = dataProtection.CreateProtector( + "Microsoft.AspNet.Authentication.Cookies.CookieAuthenticationMiddleware", // full name of the ASP.NET 5 type + CookieAuthenticationDefaults.AuthenticationType, "v2"); + var builder = new WebApplicationBuilder() .Configure(app => { @@ -157,14 +92,19 @@ public async Task InteropWithNewCookieContainsIdentity() app.Run(context => context.Authentication.SignInAsync("Cookies", user)); }) .ConfigureServices(services => services.AddAuthentication()); - var newServer = new TestHost.TestServer(builder); + var newServer = new AspNet.TestHost.TestServer(builder); var cookie = await SendAndGetCookie(newServer, "http://example.com/login"); var server = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; - app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); + + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + TicketDataFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector)) + }); + app.Run(async context => { var result = await context.Authentication.AuthenticateAsync("Cookies"); @@ -177,7 +117,7 @@ public async Task InteropWithNewCookieContainsIdentity() Assert.Equal("Alice", FindClaimValue(transaction2, ClaimTypes.Name)); } - private static async Task SendAndGetCookie(TestHost.TestServer server, string uri) + private static async Task SendAndGetCookie(AspNet.TestHost.TestServer server, string uri) { var request = new HttpRequestMessage(HttpMethod.Get, uri); var response = await server.CreateClient().SendAsync(request); @@ -271,4 +211,3 @@ private class Transaction } } - diff --git a/test/Microsoft.Owin.Security.Cookies.Interop.Test/Microsoft.Owin.Security.Cookies.Interop.Test.xproj b/test/Microsoft.Owin.Security.Interop.Test/Microsoft.Owin.Security.Interop.Test.xproj similarity index 88% rename from test/Microsoft.Owin.Security.Cookies.Interop.Test/Microsoft.Owin.Security.Cookies.Interop.Test.xproj rename to test/Microsoft.Owin.Security.Interop.Test/Microsoft.Owin.Security.Interop.Test.xproj index 3341cf4e6..c3f5e576d 100644 --- a/test/Microsoft.Owin.Security.Cookies.Interop.Test/Microsoft.Owin.Security.Cookies.Interop.Test.xproj +++ b/test/Microsoft.Owin.Security.Interop.Test/Microsoft.Owin.Security.Interop.Test.xproj @@ -6,8 +6,8 @@ - 73e8e654-a2ac-4848-95f3-eb55512f6c39 - Microsoft.Owin.Security.Cookies.Interop.Test + a2b5dc39-68d5-4145-a8cc-6aeab7d33a24 + Microsoft.Owin.Security.Interop.Test ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/test/Microsoft.Owin.Security.Interop.Test/Properties/AssemblyInfo.cs b/test/Microsoft.Owin.Security.Interop.Test/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..10b3c4ae5 --- /dev/null +++ b/test/Microsoft.Owin.Security.Interop.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.Owin.Security.Interop.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Microsoft.Owin.Security.Interop.Test")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a2b5dc39-68d5-4145-a8cc-6aeab7d33a24")] diff --git a/test/Microsoft.Owin.Security.Interop.Test/TicketInteropTests.cs b/test/Microsoft.Owin.Security.Interop.Test/TicketInteropTests.cs new file mode 100644 index 000000000..781080552 --- /dev/null +++ b/test/Microsoft.Owin.Security.Interop.Test/TicketInteropTests.cs @@ -0,0 +1,91 @@ +// 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.Linq; +using System.Security.Claims; +using Microsoft.AspNet.Authentication; +using Xunit; + +namespace Microsoft.Owin.Security.Interop.Test +{ + public class TicketInteropTests + { + [Fact] + public void NewSerializerCanReadInteropTicket() + { + var identity = new ClaimsIdentity("scheme"); + identity.AddClaim(new Claim("Test", "Value")); + + var expires = DateTime.Today; + var issued = new DateTime(1979, 11, 11); + var properties = new Owin.Security.AuthenticationProperties(); + properties.IsPersistent = true; + properties.RedirectUri = "/redirect"; + properties.Dictionary["key"] = "value"; + properties.ExpiresUtc = expires; + properties.IssuedUtc = issued; + + var interopTicket = new Owin.Security.AuthenticationTicket(identity, properties); + var interopSerializer = new AspNetTicketSerializer(); + + var bytes = interopSerializer.Serialize(interopTicket); + + var newSerializer = new TicketSerializer(); + var newTicket = newSerializer.Deserialize(bytes); + + Assert.NotNull(newTicket); + Assert.Equal(1, newTicket.Principal.Identities.Count()); + var newIdentity = newTicket.Principal.Identity as ClaimsIdentity; + Assert.NotNull(newIdentity); + Assert.Equal("scheme", newIdentity.AuthenticationType); + Assert.True(newIdentity.HasClaim(c => c.Type == "Test" && c.Value == "Value")); + Assert.NotNull(newTicket.Properties); + Assert.True(newTicket.Properties.IsPersistent); + Assert.Equal("/redirect", newTicket.Properties.RedirectUri); + Assert.Equal("value", newTicket.Properties.Items["key"]); + Assert.Equal(expires, newTicket.Properties.ExpiresUtc); + Assert.Equal(issued, newTicket.Properties.IssuedUtc); + } + + [Fact] + public void InteropSerializerCanReadNewTicket() + { + var user = new ClaimsPrincipal(); + var identity = new ClaimsIdentity("scheme"); + identity.AddClaim(new Claim("Test", "Value")); + user.AddIdentity(identity); + + var expires = DateTime.Today; + var issued = new DateTime(1979, 11, 11); + var properties = new AspNet.Http.Authentication.AuthenticationProperties(); + properties.IsPersistent = true; + properties.RedirectUri = "/redirect"; + properties.Items["key"] = "value"; + properties.ExpiresUtc = expires; + properties.IssuedUtc = issued; + + var newTicket = new AspNet.Authentication.AuthenticationTicket(user, properties, "scheme"); + var newSerializer = new TicketSerializer(); + + var bytes = newSerializer.Serialize(newTicket); + + var interopSerializer = new AspNetTicketSerializer(); + var interopTicket = interopSerializer.Deserialize(bytes); + + Assert.NotNull(interopTicket); + var newIdentity = interopTicket.Identity; + Assert.NotNull(newIdentity); + Assert.Equal("scheme", newIdentity.AuthenticationType); + Assert.True(newIdentity.HasClaim(c => c.Type == "Test" && c.Value == "Value")); + Assert.NotNull(interopTicket.Properties); + Assert.True(interopTicket.Properties.IsPersistent); + Assert.Equal("/redirect", interopTicket.Properties.RedirectUri); + Assert.Equal("value", interopTicket.Properties.Dictionary["key"]); + Assert.Equal(expires, interopTicket.Properties.ExpiresUtc); + Assert.Equal(issued, interopTicket.Properties.IssuedUtc); + } + } +} + + diff --git a/test/Microsoft.Owin.Security.Cookies.Interop.Test/project.json b/test/Microsoft.Owin.Security.Interop.Test/project.json similarity index 78% rename from test/Microsoft.Owin.Security.Cookies.Interop.Test/project.json rename to test/Microsoft.Owin.Security.Interop.Test/project.json index c206ad20e..585c87aa1 100644 --- a/test/Microsoft.Owin.Security.Cookies.Interop.Test/project.json +++ b/test/Microsoft.Owin.Security.Interop.Test/project.json @@ -1,11 +1,12 @@ -{ +{ "compilationOptions": { "warningsAsErrors": true }, "dependencies": { "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Owin.Security.Cookies.Interop": "1.0.0-*", + "Microsoft.Owin.Security.Cookies": "3.0.1", + "Microsoft.Owin.Security.Interop": "1.0.0-*", "Microsoft.Owin.Testing": "3.0.1", "xunit.runner.aspnet": "2.0.0-aspnet-*" },