Replace Microsoft.Owin.Security.Cookies.Interop by Microsoft.Owin.Security.Interop
This commit is contained in:
parent
5bcc1bfc26
commit
f4aafe04e0
60
Security.sln
60
Security.sln
|
|
@ -50,12 +50,12 @@ 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}"
|
||||
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}"
|
||||
EndProject
|
||||
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.Interop", "src\Microsoft.Owin.Security.Interop\Microsoft.Owin.Security.Interop.xproj", "{A7922DD8-09F1-43E4-938B-CC523EA08898}"
|
||||
EndProject
|
||||
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
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ namespace Microsoft.AspNet.Authentication
|
|||
{
|
||||
public class TicketDataFormat : SecureDataFormat<AuthenticationTicket>
|
||||
{
|
||||
public TicketDataFormat(IDataProtector protector) : base(new TicketSerializer(), protector)
|
||||
public TicketDataFormat(IDataProtector protector)
|
||||
: base(TicketSerializer.Default, protector)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Security.Claims;
|
|||
|
||||
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<AuthenticationTicket>
|
||||
{
|
||||
private const string DefaultStringPlaceholder = "\0";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Helpful constants for working with the authentication cookie compatibility shim.
|
||||
/// </summary>
|
||||
public static class DefaultCompatibilityConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// The default authentication type for application authentication cookies.
|
||||
/// </summary>
|
||||
public const string ApplicationCookieAuthenticationType = "Microsoft.AspNet.Identity.Application.AuthType";
|
||||
|
||||
/// <summary>
|
||||
/// The default cookie name for application authentication cookies.
|
||||
/// Used by <see cref="CookieAuthenticationOptions.CookieName"/>.
|
||||
/// </summary>
|
||||
public const string CookieName = ".AspNet.Microsoft.AspNet.Identity.Application";
|
||||
}
|
||||
}
|
||||
|
|
@ -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")]
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,12 @@ using Microsoft.Owin.Security.DataHandler;
|
|||
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<AuthenticationTicket>
|
||||
{
|
||||
public AspNetTicketDataFormat(IDataProtector protector)
|
||||
: base(new AspNetTicketSerializer(), protector, TextEncodings.Base64Url)
|
||||
: base(AspNetTicketSerializer.Default, protector, TextEncodings.Base64Url)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
|||
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<AuthenticationTicket>
|
||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.Owin.Security.Cookies.Interop
|
|||
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)
|
||||
{
|
||||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
using Microsoft.AspNet.DataProtection;
|
||||
|
||||
namespace Microsoft.Owin.Security.Cookies.Interop
|
||||
namespace Microsoft.Owin.Security.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an <see cref="IDataProtector"/> to an
|
||||
/// <see cref="Microsoft.Owin.Security.DataProtection.IDataProtector"/>.
|
||||
/// </summary>
|
||||
internal sealed class DataProtectorShim : Microsoft.Owin.Security.DataProtection.IDataProtector
|
||||
public sealed class DataProtectorShim : Microsoft.Owin.Security.DataProtection.IDataProtector
|
||||
{
|
||||
private readonly IDataProtector _protector;
|
||||
|
||||
|
|
@ -4,16 +4,17 @@
|
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>21a56e78-31de-4868-9778-7e4dbe2a4e35</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Owin.Security.Cookies.Shareable</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
<ProjectGuid>a7922dd8-09f1-43e4-938b-cc523ea08898</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Owin.Security.Interop</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -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")]
|
||||
|
|
@ -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": { }
|
||||
}
|
||||
}
|
||||
|
|
@ -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 @@ namespace Microsoft.AspNet.CookiePolicy.Test
|
|||
});
|
||||
})
|
||||
.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 @@ namespace Microsoft.AspNet.CookiePolicy.Test
|
|||
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 @@ namespace Microsoft.AspNet.CookiePolicy.Test
|
|||
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 @@ namespace Microsoft.AspNet.CookiePolicy.Test
|
|||
Assert.Equal("Alice", FindClaimValue(transaction2, ClaimTypes.Name));
|
||||
}
|
||||
|
||||
private static async Task<string> SendAndGetCookie(TestHost.TestServer server, string uri)
|
||||
private static async Task<string> 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 @@ namespace Microsoft.AspNet.CookiePolicy.Test
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -6,8 +6,8 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>73e8e654-a2ac-4848-95f3-eb55512f6c39</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Owin.Security.Cookies.Interop.Test</RootNamespace>
|
||||
<ProjectGuid>a2b5dc39-68d5-4145-a8cc-6aeab7d33a24</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Owin.Security.Interop.Test</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
|
@ -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")]
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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-*"
|
||||
},
|
||||
Loading…
Reference in New Issue