From 647b863d6f255ad4b85b20943c582f3384935bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 18 Oct 2019 09:53:17 +0300 Subject: [PATCH] Configure IdentityServer database mapping based on the database provider. --- .../EfCoreDatabaseProvider.cs | 14 +++++++ ...yServerDbContextModelCreatingExtensions.cs | 41 +++++++++++++++++-- ...yServerModelBuilderConfigurationOptions.cs | 3 ++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProvider.cs diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProvider.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProvider.cs new file mode 100644 index 0000000000..0ec8e4e469 --- /dev/null +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EfCoreDatabaseProvider.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.EntityFrameworkCore +{ + public enum EfCoreDatabaseProvider + { + SqlServer, + MySql, + Oracle, + PostgreSql, + Sqlite, + InMemory, + Cosmos, + Firebird + } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs index a9b1f1fe33..3efeb9cc4c 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; @@ -71,7 +72,14 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore redirectUri.HasKey(x => new { x.ClientId, x.RedirectUri }); - redirectUri.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLength).IsRequired(); + if (options.DatabaseProvider == EfCoreDatabaseProvider.MySql) + { + redirectUri.Property(x => x.RedirectUri).HasMaxLength(300).IsRequired(); + } + else + { + redirectUri.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLength).IsRequired(); + } }); builder.Entity(postLogoutRedirectUri => @@ -80,7 +88,14 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore postLogoutRedirectUri.HasKey(x => new { x.ClientId, x.PostLogoutRedirectUri }); - postLogoutRedirectUri.Property(x => x.PostLogoutRedirectUri).HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLength).IsRequired(); + if (options.DatabaseProvider == EfCoreDatabaseProvider.MySql) + { + postLogoutRedirectUri.Property(x => x.PostLogoutRedirectUri).HasMaxLength(300).IsRequired(); + } + else + { + postLogoutRedirectUri.Property(x => x.PostLogoutRedirectUri).HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLength).IsRequired(); + } }); builder.Entity(scope => @@ -99,7 +114,16 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore secret.HasKey(x => new { x.ClientId, x.Type, x.Value }); secret.Property(x => x.Type).HasMaxLength(SecretConsts.TypeMaxLength).IsRequired(); - secret.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLength).IsRequired(); + + if (options.DatabaseProvider == EfCoreDatabaseProvider.MySql) + { + secret.Property(x => x.Value).HasMaxLength(300).IsRequired(); + } + else + { + secret.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLength).IsRequired(); + } + secret.Property(x => x.Description).HasMaxLength(SecretConsts.DescriptionMaxLength); }); @@ -214,7 +238,16 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore apiSecret.HasKey(x => new { x.ApiResourceId, x.Type, x.Value }); apiSecret.Property(x => x.Type).HasMaxLength(SecretConsts.TypeMaxLength).IsRequired(); - apiSecret.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLength).IsRequired(); + + if (options.DatabaseProvider == EfCoreDatabaseProvider.MySql) + { + apiSecret.Property(x => x.Value).HasMaxLength(300).IsRequired(); + } + else + { + apiSecret.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLength).IsRequired(); + } + apiSecret.Property(x => x.Description).HasMaxLength(SecretConsts.DescriptionMaxLength); }); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs index 55dcc06837..1f7cccf472 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs @@ -1,10 +1,13 @@ using JetBrains.Annotations; +using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; namespace Volo.Abp.IdentityServer.EntityFrameworkCore { public class IdentityServerModelBuilderConfigurationOptions : ModelBuilderConfigurationOptions { + public EfCoreDatabaseProvider? DatabaseProvider { get; set; } + public IdentityServerModelBuilderConfigurationOptions( [NotNull] string tablePrefix, [CanBeNull] string schema)