Starts in:
2 DAYS
4 HRS
3 MIN
10 SEC
Starts in:
2 D
4 H
3 M
10 S

Migrating from OpenIddict to IdentityServer4 Step by Step Guide

ABP startup templates use OpenIddict OpenID provider from v6.0.0 by default and IdentityServer projects are renamed to AuthServer in tiered/separated solutions. Since OpenIddict is the default OpenID provider library for ABP templates since v6.0, you may want to keep using IdentityServer4 library, even it is archived and no longer maintained by the owners. ABP doesn't provide support for newer versions of IdentityServer. This guide provides layer-by-layer guidance for migrating your existing OpenIddict application to IdentityServer4.

IdentityServer4 Migration Steps

Use the abp update command to update your existing application. See Upgrading docs for more info. Apply required migrations by following the Migration Guides based on your application version.

Domain.Shared Layer

  • In MyApplication.Domain.Shared.csproj replace project reference:
<PackageReference Include="Volo.Abp.OpenIddict.Domain.Shared" Version="6.0.*" />

with

<PackageReference Include="Volo.Abp.IdentityServer.Domain.Shared" Version="6.0.*" />
  • In MyApplicationDomainSharedModule.cs replace usings and module dependencies:
using Volo.Abp.OpenIddict;
...
typeof(AbpOpenIddictDomainSharedModule)

with

using Volo.Abp.IdentityServer;
...
typeof(AbpIdentityServerDomainSharedModule)

Domain Layer

  • In MyApplication.Domain.csproj replace project references:
<PackageReference Include="Volo.Abp.OpenIddict.Domain" Version="6.0.*" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.OpenIddict" Version="6.0.*" />

with

<PackageReference Include="Volo.Abp.IdentityServer.Domain" Version="6.0.*" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.IdentityServer" Version="6.0.*" />
  • In MyApplicationDomainModule.cs replace usings and module dependencies:
using Volo.Abp.OpenIddict;
using Volo.Abp.PermissionManagement.OpenIddict;
...
typeof(AbpOpenIddictDomainModule),
typeof(AbpPermissionManagementDomainOpenIddictModule),

with

using Volo.Abp.IdentityServer;
using Volo.Abp.PermissionManagement.IdentityServer;
...
typeof(AbpIdentityServerDomainModule),
typeof(AbpPermissionManagementDomainIdentityServerModule),

OpenIddictDataSeedContributor

DataSeeder is the most important part for starting the application since it seeds the initial data for both OpenID providers.

  • Create a folder named IdentityServer under the Domain project and copy the IdentityServerDataSeedContributor.cs under this folder. Rename all the OpenId2Ids with your project name.
  • Delete OpenIddict folder that contains OpenIddictDataSeedContributor.cs which is no longer needed.

EntityFrameworkCore Layer

If you are using MongoDB, skip this step and check the MongoDB layer section.

  • In MyApplication.EntityFrameworkCore.csproj replace project reference:

    <PackageReference Include="Volo.Abp.OpenIddict.EntityFrameworkCore" Version="6.0.*" />
    

    with

    <PackageReference Include="Volo.Abp.IdentityServer.EntityFrameworkCore" Version="6.0.*" />
    
  • In MyApplicationEntityFrameworkCoreModule.cs replace usings and module dependencies:

using Volo.Abp.OpenIddict.EntityFrameworkCore;
...
typeof(AbpOpenIddictEntityFrameworkCoreModule),

with

using Volo.Abp.IdentityServer.EntityFrameworkCore;
...
typeof(AbpIdentityServerEntityFrameworkCoreModule),
  • In MyApplicationDbContext.cs replace usings and fluent api configurations:

    using Volo.Abp.OpenIddict.EntityFrameworkCore;
    ...
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
    
        /* Include modules to your migration db context */
    
        ...
        builder.ConfigureOpenIddict();
    

    with

    using Volo.Abp.IdentityServer.EntityFrameworkCore;
    ...
    using Volo.Abp.OpenIddict.EntityFrameworkCore;
    ...
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
    
        /* Include modules to your migration db context */
    
        ...
        builder.ConfigureIdentityServer();
    

Not: You need to create new migration after updating the fluent api. Navigate to EntityFrameworkCore folder and add a new migration. Ex, dotnet ef migrations add Updated_To_IdentityServer

MongoDB Layer

If you are using EntityFrameworkCore, skip this step and check the EntityFrameworkCore layer section.

  • In MyApplication.MongoDB.csproj replace project reference:

    <PackageReference Include="Volo.Abp.OpenIddict.MongoDB" Version="6.0.*" />
    

    with

    <PackageReference Include="Volo.Abp.IdentityServer.MongoDB" Version="6.0.*" />
    
  • In MyApplicationMongoDbModule.cs replace usings and module dependencies:

using Volo.Abp.OpenIddict.MongoDB;
...
typeof(AbpOpenIddictMongoDbModule),

with

using Volo.Abp.IdentityServer.MongoDB;
...
typeof(AbpIdentityServerMongoDbModule),

DbMigrator Project

  • In appsettings.json replace OpenIddict section with IdentityServer since IdentityServerDataSeeder will be using these information for initial data seeding:

    "IdentityServer": { // Rename OpenIddict to IdentityServer
        "Clients ": {	// Rename Applications to Clients
          ...
        }
      }
    

Test Project

  • In MyApplicationTestBaseModule.cs add the IdentityServer related using and PreConfigurations:

    using Volo.Abp.IdentityServer;
    

    and

    PreConfigure<AbpIdentityServerBuilderOptions>(options =>
    {
        options.AddDeveloperSigningCredential = false;
    });
    
    PreConfigure<IIdentityServerBuilder>(identityServerBuilder =>
    {
        identityServerBuilder.AddDeveloperSigningCredential(false, System.Guid.NewGuid().ToString());
    });
    

    to PreConfigureServices to run authentication related unit tests.

UI Layer

You can follow the migrations guides from IdentityServer to OpenIddict in reverse order to update your UIs. You can also check the source-code for Index.cshtml.cs and Index.cshtml files for AuthServer project.

Source code of samples and module

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More