IdentityServer4.Contrib.NHibernate 3.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package IdentityServer4.Contrib.NHibernate --version 3.0.3
NuGet\Install-Package IdentityServer4.Contrib.NHibernate -Version 3.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IdentityServer4.Contrib.NHibernate" Version="3.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IdentityServer4.Contrib.NHibernate --version 3.0.3
#r "nuget: IdentityServer4.Contrib.NHibernate, 3.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IdentityServer4.Contrib.NHibernate as a Cake Addin
#addin nuget:?package=IdentityServer4.Contrib.NHibernate&version=3.0.3

// Install IdentityServer4.Contrib.NHibernate as a Cake Tool
#tool nuget:?package=IdentityServer4.Contrib.NHibernate&version=3.0.3

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 mappings, so to have the least number of dependencies. All mappings are defined using the integrated Mapping By Code feature and the Loquacious API.

Current 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:

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
  • For PostgreSQL: Install-Package Npgsql
  • For MySQL: Install-Package MySql.Data

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.

Contributors

I wish to thank all the contributors to this project:

Acknowledgements

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

And obviously, IdentityServer. 😃

Thanks everybody for the great work!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0 2,047 3/14/2022
3.0.4 1,563 9/6/2021
3.0.3 1,732 6/13/2021
3.0.2 487 9/29/2020
3.0.1 463 9/3/2020
3.0.0 767 7/30/2020
2.1.4 351 9/6/2021
2.1.3 367 6/14/2021
2.1.2 496 9/29/2020
2.1.1 463 9/14/2020
2.1.0 556 5/17/2020
2.0.4 353 9/6/2021
2.0.3 388 6/14/2021
2.0.2 488 9/29/2020
2.0.1 505 9/14/2020
2.0.0 574 11/30/2019
1.1.8 338 9/6/2021
1.1.7 363 6/14/2021
1.1.6 490 9/29/2020
1.1.5 462 9/14/2020
1.1.4 644 6/6/2020
1.1.2 518 11/17/2019
1.1.1 510 9/22/2019
1.1.0 562 7/8/2019
1.1.0-beta.1 303 2/15/2019