Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Add Interop 45 Compat package
Browse files Browse the repository at this point in the history
Initial samples fixes (more coming to make things work)
  • Loading branch information
HaoK committed May 23, 2016
1 parent 104f216 commit e067629
Show file tree
Hide file tree
Showing 94 changed files with 460 additions and 316 deletions.
32 changes: 31 additions & 1 deletion Identity.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F647068-6602-4E24-B1DC-8ED91481A50A}"
EndProject
Expand All @@ -27,6 +27,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Identi
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Identity.EntityFrameworkCore", "src\Microsoft.AspNetCore.Identity.EntityFrameworkCore\Microsoft.AspNetCore.Identity.EntityFrameworkCore.xproj", "{4490894C-3572-4E63-86F1-EE5105CE8A06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interop4.5", "samples\Interop4.5\Interop4.5.csproj", "{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Identity.CoreCompat", "src\Microsoft.AspNet.Identity.CoreCompat\Microsoft.AspNet.Identity.CoreCompat.xproj", "{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -107,6 +111,30 @@ Global
{4490894C-3572-4E63-86F1-EE5105CE8A06}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4490894C-3572-4E63-86F1-EE5105CE8A06}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4490894C-3572-4E63-86F1-EE5105CE8A06}.Release|x86.ActiveCfg = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|x86.ActiveCfg = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Debug|x86.Build.0 = Debug|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|Any CPU.Build.0 = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|x86.ActiveCfg = Release|Any CPU
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578}.Release|x86.Build.0 = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|x86.ActiveCfg = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Debug|x86.Build.0 = Debug|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|Any CPU.Build.0 = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|x86.ActiveCfg = Release|Any CPU
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -119,5 +147,7 @@ Global
{37236EA3-915D-46D5-997C-DF513C500E4B} = {52D59F18-62D2-4D17-8CF2-BE192445AF8E}
{EA7EB28F-53B8-4009-9C6B-74DB090CA8DD} = {52D59F18-62D2-4D17-8CF2-BE192445AF8E}
{4490894C-3572-4E63-86F1-EE5105CE8A06} = {0F647068-6602-4E24-B1DC-8ED91481A50A}
{4D30B14B-20FC-4DDA-97C5-B32D13FE2578} = {58D94A0E-C2B7-43A7-8826-99ECBB1E0A50}
{6A74C6EA-B241-4D6B-BCE4-BF89EC1D2475} = {0F647068-6602-4E24-B1DC-8ED91481A50A}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
Expand Down
2 changes: 2 additions & 0 deletions samples/IdentitySample.Mvc/Models/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace IdentitySample.Models
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions options) : base(options) { }

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
Expand Down
24 changes: 24 additions & 0 deletions samples/IdentitySample.Mvc/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

namespace IdentitySample
{
public static class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();

var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
6 changes: 6 additions & 0 deletions samples/IdentitySample.Mvc/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"environmentVariables": {
"ASPNET_ENVIRONMENT": "Development"
}
},
"web": {
"commandName": "web",
"environmentVariables": {
"ASPNET_ENVIRONMENT": "Development"
}
}
}
}
15 changes: 2 additions & 13 deletions samples/IdentitySample.Mvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

Expand All @@ -47,8 +48,8 @@ public void ConfigureServices(IServiceCollection services)

services.AddIdentity<ApplicationUser, IdentityRole>(options => {
options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
options.Cookies.ApplicationCookie.CookieName = "Interop";
options.Cookies.ApplicationCookie.DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Expand Down Expand Up @@ -114,18 +115,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
template: "{controller=Home}/{action=Index}/{id?}");
});
}

// Entry point for the application.
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}

2 changes: 1 addition & 1 deletion samples/IdentitySample.Mvc/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-controller="Home" asp-action="Index" class="navbar-brand">$safeprojectname$</a>
<a asp-controller="Home" asp-action="Index" class="navbar-brand">Identity Sample</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
Expand Down
2 changes: 1 addition & 1 deletion samples/IdentitySample.Mvc/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=Interop11-23;Trusted_Connection=True;MultipleActiveResultSets=true"
"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=Interop-Shared;Trusted_Connection=True;MultipleActiveResultSets=true"
}
},
"Logging": {
Expand Down
3 changes: 2 additions & 1 deletion samples/IdentitySample.Mvc/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"Microsoft.Extensions.Logging.Debug": "1.0.0-*"
},
"buildOptions": {
"emitEntryPoint": true
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"frameworks": {
"net451": {},
Expand Down
30 changes: 30 additions & 0 deletions samples/IdentitySample.Mvc/web.Debug.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
31 changes: 31 additions & 0 deletions samples/IdentitySample.Mvc/web.Release.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Web;
using System.Web.Optimization;

namespace Interop45
namespace Interop4._5
{
public class BundleConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Web;
using System.Web.Mvc;

namespace Interop45
namespace Interop4._5
{
public class FilterConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.Owin;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Interop45.Models;
using Microsoft.AspNetCore.Identity.Compat;
using Interop4._5.Models;

namespace Interop45
namespace Interop4._5
{
public class EmailService : IIdentityMessageService
{
Expand Down Expand Up @@ -43,7 +42,7 @@ public ApplicationUserManager(IUserStore<ApplicationUser> store)

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new IdentityUserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for usernames
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Web.Mvc;
using System.Web.Routing;

namespace Interop45
namespace Interop4._5
{
public class RouteConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.Owin;
using System;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
using Interop45.Models;
using Microsoft.AspNetCore.DataProtection;
using Interop4._5.Models;
using System.IO;

namespace Interop45
namespace Interop4._5
{
public partial class Startup
{
Expand All @@ -26,17 +25,18 @@ public void ConfigureAuth(IAppBuilder app)
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieName = "Interop",
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
}, new DataProtectionProvider(new DirectoryInfo("C:\\Github\\Identity\\artifacts")));
},
TicketDataFormat = CookieInterop.CreateSharedDataFormat(new DirectoryInfo("C:\\Github\\Identity\\artifacts"), DefaultAuthenticationTypes.ApplicationCookie)
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
Expand Down Expand Up @@ -67,4 +67,24 @@ public void ConfigureAuth(IAppBuilder app)
//});
}
}
}
}

// Temporary Copy from CookieInterop in CoreCompat, samples should reference that
namespace Owin
{
using System.IO;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Interop;

public static class CookieInterop
{
public static ISecureDataFormat<AuthenticationTicket> CreateSharedDataFormat(DirectoryInfo keyDirectory, string authenticationType)
{
var dataProtector = DataProtectionProvider.Create(keyDirectory)
.CreateProtector("Microsoft.AspNet.Authentication.Cookies.CookieAuthenticationMiddleware", // full name of the ASP.NET 5 type
authenticationType, "v2");
return new AspNetTicketDataFormat(new DataProtectorShim(dataProtector));
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using System;
using System.Globalization;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.Owin;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using Interop45.Models;
using Interop4._5.Models;

namespace Interop45.Controllers
namespace Interop4._5.Controllers
{
[Authorize]
public class AccountController : Controller
Expand Down
Loading

0 comments on commit e067629

Please sign in to comment.