Coder Social home page Coder Social logo

flam1980 / aspnetcore.identity.postgresql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robson-paproski/aspnetcore.identity.postgresql

0.0 0.0 0.0 932 KB

Identity for PostgreSQL using .Net Core and Npgsql

License: Other

JavaScript 0.02% C# 99.69% CSS 0.29%

aspnetcore.identity.postgresql's Introduction

AspNetCore Identity Provider for PostgreSQL

Identity for PostgreSQL using the .Net Core 2.0

Installation

Install as NuGet package:

Install-Package AspNetCore.Identity.PostgreSQL.dll

Usage

Follow the steps below to add to your project

  1. Add services.AddSingleton(_ => Configuration); inside the scope of ConfigureServices(IServiceCollection services) in your Startup.cs class. The identity gonna use the default Dependency Injection of .net core to use your connectionId from your environment specific file.

  2. In your appsetings.Development and .Production, you should add a PostgreSQLBaseConnection string.

  {
 "ConnectionStrings": {
   "PostgreSQLBaseConnection": "Server = SERVER; Port = 5432; Database = DB; User Id = USER; Password = PASSWORD; Pooling=false; Keepalive=10"
 }
}
  1. In your ApplicationUser class inside Models folder, change using Microsoft.AspNetCore.Identity; to using AspNetCore.Identity.PostgreSQL;

  2. In your startup.cs class remove any reference to the ApplicationDbContext and the line
    .AddEntityFrameworkStores() below
    services.AddIdentity<ApplicationUser, IdentityRole>()

  3. In your startup class, add the following lines bellow services.AddIdentity<ApplicationUser, IdentityRole>()

    .AddUserStore<UserStore<ApplicationUser>>()  
    .AddRoleStore<RoleStore<IdentityRole>>() 
    
  4. In your startup class, add using IdentityRole = AspNetCore.Identity.PostgreSQL.IdentityRole; in the using section.

  5. Last but not least, execute the SQL script found in the solution items against your database in pgAdmin (or via the command line).

After all done, maybe appears some Conversions Guid to String errors. Just put .ToString after User.Id and that's it. That occurours

This repo also contains a test project. You just need to modifiy the appSettings..json to connect to your database, and exec the SQL script included.

To configure the name of connection string that will be used, you can put IdentityDbConfig.StringConnectionName= "ConnectionStringName"; in your Startup.cs

For a brand new project

You should modify program.cs to include the appsettings.Development config file.

            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .ConfigureAppConfiguration((context, config) =>
                {
                    IHostingEnvironment env = context.HostingEnvironment;

                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
                })
                .Build();

If you have any questions feel free to open an issue

aspnetcore.identity.postgresql's People

Contributors

robson-paproski avatar totano avatar

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.