Giter Site home page Giter Site logo

aspnetcore-identity-arangodb's Introduction

ASP.NET Core Identity library for ArangoDB

Install

PM> Install-Package BorderEast.ASPNetCore.Identity.ArangoDB

Setting up Guide

See the SampleWebAppliction project for a working example, or follow these steps.

1 Create a new ASP.NET Core web application and choose Individual User Accounts for the Authentication method.

2 Add reference to DotNetCore ArangoDB Driver & Identity

  • PM> Install-Package Microsoft.AspNetCore.Identity or search NuGet Gallery for Microsoft.AspNetCore.Identity.
  • PM> Install-Package BorderEast.ArangoDB.Client or search NuGet Gallery for BorderEast.ArangoDB.Client.
  • PM> Install-Package BorderEast.ASPNetCore.Identity.ArangoDB

Rebuild and ensure BorderEast namespace is available (In VS2017 I had to close and reopen solution. Bug?).

3 Remove dependencies to Entity Framework

  • Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.SqlServer.Design
  • Microsoft.EntityFrameworkCore.Tools

4 Remove EF Related Items

  • Delete Data folder containing migrations and ApplicationDbContext.cs

  • Remove all using statements refering to Entity Framework

  • Change reference on base class IdentityUser on Models.ApplicationUser from the removed EF using statement to BorderEast.ASPNetCore.Identity.ArangoDB; and add this annotation [JsonObject(Id = "IdentityUser")]

  • Remove the following code in Startup.cs

    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

    services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders();

    app.UseDatabaseErrorPage();

Proejct should now compile

5 Add ArangoDB Identity

In Startup.cs, add the following to ConfigureServices:

        ArangoClient.Client().SetDefaultDatabase(new BorderEast.ArangoDB.Client.Database.ClientSettings()
        {
            DatabaseName = "_system",
            Protocol = BorderEast.ArangoDB.Client.Database.ProtocolType.HTTP,
            ServerAddress = "localhost",
            ServerPort = 8529,
            SystemCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")),
            DatabaseCredential = new System.Net.NetworkCredential("root", Environment.GetEnvironmentVariable("USERNAME")),
            AutoCreate = true,
            HTTPClient = new System.Net.Http.HttpClient(),
            IsDebug = true
        });

        services.AddSingleton<IArangoClient>(ArangoClient.Client());

        services.AddIdentity<ApplicationUser, IdentityRole>()
        .AddArangoDbStores()
        .AddDefaultTokenProviders();

Ensure this is all added before the services.AddMvc(); statement.

6 Setup ArangoDB

Ensure ArangoDB is installed and adjust the database/username/password settings above. To run as is, set the root password to your machine username (run echo %USERNAME% on cmd line) and create the IdentityUser and IdentityRole collections in the your database using the following script:

		db._create("IdentityUser");
		db._create("IdentityRole");

		db.IdentityUser.ensureIndex({ type: "hash", fields: [ "normalizedUserName" ], unique: true });
		db.IdentityUser.ensureIndex({ type: "hash", fields: [ "normalizedEmail" ], unique: true });
		db.IdentityUser.ensureIndex({ type: "hash", fields: [ "logins[*].providerKey" ] });

aspnetcore-identity-arangodb's People

Contributors

agrothe avatar irriss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

irriss orhanrauf

aspnetcore-identity-arangodb's Issues

Bug in FindByLoginAsync

Hi there,
Excellent job with this project.
However, I faced an issue trying to use method UserStore.FindByLoginAsync

It uses
var user = await client.DB().GetByExampleAsync<TUser>(new { logins = new { loginProvider = loginProvider, providerKey = providerKey } });

Which does not work for at least two reasons:

  1. logins is an array
  2. there might be other attributes in the login so it will not match

Any expectations for this bug to be fixed?

Thanks for great job

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.