Skip to content

Commit

Permalink
Updated for v1 Nightly feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rustd authored and rustd committed Oct 9, 2013
1 parent 3738ae8 commit 776680f
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 256 deletions.
43 changes: 20 additions & 23 deletions AspnetIdentitySample/App_Start/IdentityConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AspnetIdentitySample.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using System;
Expand All @@ -14,48 +15,44 @@ namespace AspnetIdentitySample
public static class IdentityConfig{
public static async void Initialize(){
var context = new MyDbContext();
AuthenticationIdentityManager IdentityManager = new AuthenticationIdentityManager(new IdentityStore(context));
var UserManager = new UserManager<MyUser>(new UserStore<MyUser>(context));
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));

string name = "Admin";
string password = "123456";
string test = "test";

//Create Role Test and User Test
await IdentityManager.Roles.CreateRoleAsync(new Role(test), CancellationToken.None);
await IdentityManager.Users.CreateLocalUserAsync(new MyUser(){ UserName=test}, password, CancellationToken.None);
await RoleManager.CreateAsync(new IdentityRole(test));
await UserManager.CreateAsync(new MyUser(){ UserName=test});

//Create Role Admin if it does not exist
var role = await IdentityManager.Roles.FindRoleByNameAsync(name, CancellationToken.None);
if (role == null)
if (!await RoleManager.RoleExistsAsync(name))
{
var roleresult = await IdentityManager.Roles.CreateRoleAsync(new Role(name), CancellationToken.None);
if (roleresult.Success)
{
role = await IdentityManager.Roles.FindRoleByNameAsync(name, CancellationToken.None);

}
var roleresult = await RoleManager.CreateAsync(new IdentityRole(name));
}

//Create User=Admin with password=123456
var user = new MyUser();
user.UserName = name;
//var adminresult = await IdentityManager.Users.CreateLocalUserAsync(user, password, CancellationToken.None);
var adminresult = await IdentityManager.Users.CreateLocalUserAsync(user, password, CancellationToken.None);
var adminresult = await UserManager.CreateAsync(user, password);

//Add User Admin to Role Admin
if (adminresult.Success)
if (adminresult.Succeeded)
{
var result = await IdentityManager.Roles.AddUserToRoleAsync(user.Id, role.Id, CancellationToken.None);
var result = await UserManager.AddToRoleAsync(user.Id, name);
}
else
{
// Add user admin to Role Admin if not already added
//Find the user Admin
var userId = await IdentityManager.Logins.GetUserIdForLocalLoginAsync(name, CancellationToken.None);
// // Add user admin to Role Admin if not already added
// //Find the user Admin
// var userId = await IdentityManager.Logins.GetUserIdForLocalLoginAsync(name, CancellationToken.None);

var rolesForUser = await IdentityManager.Roles.GetRolesForUserAsync(userId, CancellationToken.None);
if (!rolesForUser.Contains(role))
{
var result = await IdentityManager.Roles.AddUserToRoleAsync(userId, role.Id, CancellationToken.None);
}
// var rolesForUser = await IdentityManager.Roles.GetRolesForUserAsync(userId, CancellationToken.None);
// if (!rolesForUser.Contains(role))
// {
// var result = await IdentityManager.Roles.AddUserToRoleAsync(userId, role.Id, CancellationToken.None);
// }
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions AspnetIdentitySample/App_Start/Startup.Auth.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Owin;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;

namespace AspnetIdentitySample
{
Expand All @@ -9,7 +12,13 @@ public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseSignInCookies();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
Expand All @@ -24,7 +33,7 @@ public void ConfigureAuth(IAppBuilder app)
// appId: "",
// appSecret: "");

app.UseGoogleAuthentication();
//app.UseGoogleAuthentication();
}
}
}
65 changes: 37 additions & 28 deletions AspnetIdentitySample/AspnetIdentitySample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,59 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.0.0-rc1\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.0.0-rc1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.1.0.0-rc1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.EntityFramework">
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.1.0.0-rc1\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.1.1.0-alpha1-130930\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.1.0-alpha1-130930\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Owin">
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.0.0-rc1\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
<Reference Include="Microsoft.AspNet.Identity.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.1.1.0-alpha1-130930\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Owin">
<HintPath>..\packages\Microsoft.Owin.2.0.0-rc1\lib\net45\Microsoft.Owin.dll</HintPath>
<Reference Include="Microsoft.Owin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Host.SystemWeb">
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.0-rc1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security">
<HintPath>..\packages\Microsoft.Owin.Security.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
<Reference Include="Microsoft.Owin.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Cookies">
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.Cookies, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Facebook">
<HintPath>..\packages\Microsoft.Owin.Security.Facebook.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.Facebook, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.Facebook.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Google">
<HintPath>..\packages\Microsoft.Owin.Security.Google.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.Google.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.Google, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.Google.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.Google.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.MicrosoftAccount">
<HintPath>..\packages\Microsoft.Owin.Security.MicrosoftAccount.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.MicrosoftAccount.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.MicrosoftAccount, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.MicrosoftAccount.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.MicrosoftAccount.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.OAuth">
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.OAuth, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Twitter">
<HintPath>..\packages\Microsoft.Owin.Security.Twitter.2.0.0-rc1\lib\net45\Microsoft.Owin.Security.Twitter.dll</HintPath>
<Reference Include="Microsoft.Owin.Security.Twitter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Owin.Security.Twitter.2.0.1-rtw1-20930-649-dev\lib\net45\Microsoft.Owin.Security.Twitter.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
Loading

0 comments on commit 776680f

Please sign in to comment.