Custom ASP.NET Identity provider for the Neo4j Graph Database
ASP.NET MVC 5 shipped with a new Identity system (in the Microsoft.AspNet.Identity.Core package) in order to support both local login and remote logins via OpenID/OAuth, but only ships with an Entity Framework provider (Microsoft.AspNet.Identity.EntityFramework).
- Upgraded Neo4jClient to 3.x - adding Bolt Support.
- You will need 2.x if you're using Neo4jClient 3+
- Drop-in replacement ASP.NET Identity with Neo4j as the backing store.
- Contains the same IdentityUser class used by the EntityFramework provider in the MVC 5 project template
- Supports additional profile properties on your application's user model.
- Provides UserStore implementation that implements the same interfaces as the EntityFramework version:
- IUserStore
- IUserLoginStore
- IUserRoleStore
- IUserClaimStore
- IUserPasswordStore
- IUserSecurityStampStore
These instructions assume you know how to set up Neo4j within an MVC application.
-
Create a new ASP.NET MVC 5 project, choosing the Individual User Accounts authentication type.
- Update all Nuget packages to latest versions (in particular 'Microsoft ASP.NET Identity Core')
- Install-Package Neo4j.Aspnet.Identity
- Remove the Entity Framework packages and replace with Neo4j Identity:
- Uninstall-Package Microsoft.AspNet.Identity.EntityFramework
- Uninstall-Package EntityFramework
-
Delete ~/Models/IdentityModels.cs
-
In ~/App_Start/IdentityConfig.cs
- Change the 'ApplicationUserManager' to use the Neo4jUserStore (as below)
- Change the 'ApplicationUserManager' to get the GraphClient from Owin (as below)
var manager = new ApplicationUserManager(new Neo4jUserStore<ApplicationUser>(context.Get<GraphClientWrapper>().GraphClient));
-
In ~/App_Start/Startup.Auth.cs
- Add 'using Neo4j.AspNet.Identity'
- Add the following Method:
private void ConfigureNeo4j(IAppBuilder app) { app.CreatePerOwinContext(() => { var gc = new GraphClient(new Uri("http://localhost.:7474/db/data")); gc.Connect(); var gcw = new GraphClientWrapper(gc); return gcw; }); }
- Replace the line about creating the ApplicationDbContext:
app.CreatePerOwinContext(ApplicationDbContext.Create);
with:
ConfigureNeo4j(app);
-
In ~/Controllers/AccountController.cs
- Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
- Add the namespace: using Neo4j.AspNet.Identity
A special thank you to David Boike and Jonathan Sheely for the inspiration provided with their projects. RavenDB ASP.NET Identity and MongoDB ASP.NET Identity respectively.
A big thank you to Antonio Sergio Simoes, for starting this whole thing up :)