Git Product home page Git Product logo

identityserver4.nhibernate's Introduction

IdentityServer4.NHibernate

IdentityServer4.NHibernate is a persistence layer for IdentityServer 4 configuration data that uses NHibernate to access the storage layer. It's heavily based on the Entity Framework Provider, in order to implement all the features required by IdentityServer.

I decided to not use FluentNHibernate for creating mappings, for having the fewest possible dependencies. All mappings are defined using the integrated Mapping By Code feature and the Loquacious API.

Current status

Build

Build status

NuGet

NuGet

Configuration

To configure the provider, simply add it to the IdentityServer configuration in the Startup class' ConfigureServices() method.

services.AddIdentityServer()
    .AddDeveloperSigningCredential()
    .AddNHibernateStores(
        Databases.SqlServer2012()
            .UsingConnectionString(Configuration["ConnectionStrings:Default"])
            .EnableSqlStatementsLogging(),
        cfgStore =>
        {
            cfgStore.DefaultSchema = "dbo";
        },
        opStore =>
        {
            opStore.DefaultSchema = "dbo";
        }
    )

In this example, we are configuring the NHibernate provider in order to:

  1. Store the configuration data in a SQL Server 2012 (or later) database, whose connection string is the one called Default in the appsettings.json file
  2. Show all the generated SQL statements in the console (EnableSqlStatementsLogging()).
  3. Put all the configuration store objects and operational store objects in the dbo schema.

Supported Databases

Currently, the provider directly supports the following databases:

  • SQL Server 2008
  • SQL Server 2012 or later.
  • SQLite.
  • SQLite in-memory (not suitable for production).

It's obviously possible to use every database supported by NHibernate.

Remember to add the required libraries to your IdentityServer project, in order to support the database you're going to use:

  • For SQL Server: Install-Package System.Data.SqlClient
  • For SQLite: Install-Package System.Data.SQLite.Core

Database Schema Creation

In the package's Scripts folder you will find the schema creation scripts for every supported database. You can use these scripts to create the database objects in the database you're going to use. Before executing, remember to modify them accordingly to your database schema.

Additional configuration options

The ConfigurationStoreOptions class has an additional EnableConfigurationStoreCache option that enables the default cache for the configuration store.

Known Issues

  1. Like the official Entity Framework provider, also this one splits the storage in two logical stores:

    • Configuration Store
    • Persisted Grant Store

    The difference here is that the Entity Framework provider configures two DbContext instances, one for each store, so theoretically, you could put the each store in a dedicated database; with this provider, both stores are managed by the same NHibernate SessionFactory, so they have to be created in the same database. It's possible to put them in different database schemas, but the database has to be the same.

  2. SQLite in-memory databases are "per-connection", so different NHibernate sessions use different databases. That's why it's not recommended to use this provider in production with an in-memory SQLite backing store.

Acknowledgements

This package has been built using these awesome Open Source projects:

And obviously, IdentityServer. :-)

Thanks everybody for the great work!

identityserver4.nhibernate's People

Contributors

albertodall 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.