Open Closed

Seperate IdentityServer and database (Single Sign On) #2733


User avatar
0
ademaygun created
  • ABP Framework version: v4.4.4

  • UI type: Angular

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): yes

  • Exception message and stack trace:

  • Steps to reproduce the issue:"

  • I created a new solution with seperate IdentityServer via following cli command: abp new Acme.BookStore --separate-identity-server -csf -dbms PostgreSql -u angular -m none -t app-pro -v 4.4.4

  • I changed connection strings

    • .host and .DbMigrator connectionstring --> Host=localhost;Port=5432;Database=BookStoreDb;User ID=postgres;Password=1234;
    • .IdentityServer connectionstring --> Host=localhost;Port=5432;Database=IdentityServerDb;User ID=postgres;Password=1234;
  • I executed dotnet run in .DbMigrator folder.

All tables created in BookStoreDb but nothing happened in IdentityServerDb. How can I create seperate IdentityServer Database ?


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can see https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#using-multiple-databases https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#separating-host-tenant-database-schemas

  • User Avatar
    0
    ademaygun created

    I created IdentityServerDbContext according to docs.

    • moved builder.ConfigureIdentityServer(); into IdentityDbContext(SecondDbContext)
    • Got relation ***does not exists(Db errors) errors, so added other (bellow) builder configurators :
    builder.ConfigureIdentityServer();
    builder.ConfigureIdentityPro();
    builder.ConfigureLanguageManagement();
    builder.ConfigureSettingManagement();
    builder.ConfigureAuditLogging();
    builder.ConfigureFeatureManagement();
    builder.ConfigureTextTemplateManagement();
     
    

    *then IDS project started with no inital data, so we run .DbMigrator project and got below error:

    
    An exception occurred while iterating over the results of a query for context type 'Volo.Abp.IdentityServer.EntityFrameworkCore.IdentityServerDbContext'.
    Npgsql.PostgresException (0x80004005): 42P01: relation "IdentityServerIdentityResources" does not exist
       at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
       at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 
    operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
      Exception data:
        Severity: ERROR
        SqlState: 42P01
        MessageText: relation "IdentityServerIdentityResources" does not exist
        Position: 41
        File: parse_relation.c
        Line: 1194
        Routine: parserOpenTable
    Npgsql.PostgresException (0x80004005): 42P01: relation "IdentityServerIdentityResources" does not exist
       at Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
       at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
       at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
       at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 
    operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
       at Volo.Abp.IdentityServer.IdentityResources.IdentityResourceRepository.CheckNameExistAsync(String name, Nullable`1 expectedId, CancellationToken cancellationToken)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.IdentityServer.IdentityResources.IdentityResourceDataSeeder.AddIdentityResourceIfNotExistsAsync(IdentityResource resource)
       at Volo.Abp.IdentityServer.IdentityResources.IdentityResourceDataSeeder.CreateStandardResourcesAsync()
       at Ekol.FFE.IdentityServer.IdentityServerDataSeedContributor.SeedAsync(DataSeedContext context) in C:\Users\Adem.aygun\repos\Ekol.FFE\aspnet-core\src\Ekol.FFE.Domain\IdentityServer\IdentityServerDataSeedContributor.cs:line 59
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Volo.Abp.Data.DataSeeder.SeedAsync(DataSeedContext context)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    

    appsettings.json: (.Host and .DbMigrator projects)

    "ConnectionStrings": {
        "Default": "Host=test;Port=5432;Database=test1;User ID=postgres;Password=****;",
        "IdentityServer":"Host=test;Port=5432;Database=idstest1;User ID=postgres;Password=****;"
      },
    
    

    We want to use IDS as an SSO for our multiple Abp projects. Are we on the correct way and how can we work dbmigrator(IdentityServerDataSeedContributor) correctly.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Here is a sample

    https://github.com/abpframework/abp-samples/tree/master/EfCoreMigrationDemo

    https://github.com/abpframework/abp-samples/blob/master/EfCoreMigrationDemo/src/BookStore.DbMigrator/appsettings.json#L3-L6

  • User Avatar
    0
    ademaygun created

    Hi Maliming, In last message I tried to explain with detail. I already seperated database connection strings and add second dbcontext, but I got error when I run dbmigrator, IdentityServerDataSeedContributor tried to run via Default connection string. It should use IdentityServer connection string.How can I do this?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try AbpIdentityServer

    "ConnectionStrings": {
        "Default": "Host=test;Port=5432;Database=test1;User ID=postgres;Password=****;",
        "AbpIdentityServer":"Host=test;Port=5432;Database=idstest1;User ID=postgres;Password=****;"
      },
    
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The connection string name of identity server module is AbpIdentityServer, you are using the IdentityServer

  • User Avatar
    0
    ademaygun created

    Hi, Regarding your message I changed connectionstring name IdentityServer --> AbpIdentityServer then db migrator worked successfully.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15