diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs index d3fa6ce923..aabfb13dc8 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs @@ -138,9 +138,7 @@ namespace Volo.Abp.IdentityServer.Clients public virtual void AddGrantType(string grantType) { - AllowedGrantTypes.Add( - new ClientGrantType(Id, grantType) - ); + AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); } public virtual void AddGrantTypes(IEnumerable grantTypes) @@ -154,14 +152,27 @@ namespace Volo.Abp.IdentityServer.Clients public virtual void AddSecret(string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) { - ClientSecrets.Add( - new ClientSecret(Id, value, expiration, type, description) - ); + ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description)); } public virtual void AddScope(string scope) { AllowedScopes.Add(new ClientScope(Id, scope)); } + + public virtual void AddCorsOrigin(string origin) + { + AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); + } + + public virtual void AddRedirectUri(string redirectUri) + { + RedirectUris.Add(new ClientRedirectUri(Id, redirectUri)); + } + + public virtual void AddPostLogoutRedirectUri(string postLogoutRedirectUri) + { + PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs index 91d55c3348..e90095db86 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs @@ -1,22 +1,26 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientCorsOrigin : Entity + public class ClientCorsOrigin : Entity { - public virtual string Origin { get; set; } + public virtual Guid ClientId { get; protected set; } - public virtual Guid ClientId { get; set; } + public virtual string Origin { get; protected set; } protected ClientCorsOrigin() { } - public ClientCorsOrigin(Guid id) + protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin) { - Id = id; + Check.NotNull(origin, nameof(origin)); + + ClientId = clientId; + Origin = origin; } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs index a1e0230f2a..0c694da631 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs @@ -1,22 +1,26 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { public class ClientPostLogoutRedirectUri : Entity { - public virtual string PostLogoutRedirectUri { get; set; } + public virtual Guid ClientId { get; protected set; } - public virtual Guid ClientId { get; set; } + public virtual string PostLogoutRedirectUri { get; protected set; } protected ClientPostLogoutRedirectUri() { } - public ClientPostLogoutRedirectUri(Guid id) + protected internal ClientPostLogoutRedirectUri(Guid clientId, [NotNull] string postLogoutRedirectUri) { - Id = id; + Check.NotNull(postLogoutRedirectUri, nameof(postLogoutRedirectUri)); + + ClientId = clientId; + PostLogoutRedirectUri = postLogoutRedirectUri; } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs index 073aae7c48..81d2bfb6de 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs @@ -1,22 +1,26 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientRedirectUri : Entity + public class ClientRedirectUri : Entity { - public virtual string RedirectUri { get; set; } + public virtual Guid ClientId { get; protected set; } - public virtual Guid ClientId { get; set; } + public virtual string RedirectUri { get; protected set; } protected ClientRedirectUri() { } - public ClientRedirectUri(Guid id) + protected internal ClientRedirectUri(Guid clientId, [NotNull] string redirectUri) { - Id = id; + Check.NotNull(redirectUri, nameof(redirectUri)); + + ClientId = clientId; + RedirectUri = redirectUri; } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs index 615607f3be..12eb717337 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs @@ -98,6 +98,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { redirectUri.ToTable(TablePrefix + "ClientRedirectUris"); + redirectUri.HasKey(x => new {x.ClientId, x.RedirectUri}); + redirectUri.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLength).IsRequired(); }); @@ -105,6 +107,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { postLogoutRedirectUri.ToTable(TablePrefix + "ClientPostLogoutRedirectUris"); + postLogoutRedirectUri.HasKey(x => new {x.ClientId, x.PostLogoutRedirectUri}); + postLogoutRedirectUri.Property(x => x.PostLogoutRedirectUri).HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLength).IsRequired(); }); @@ -147,6 +151,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { corsOrigin.ToTable(TablePrefix + "ClientCorsOrigins"); + corsOrigin.HasKey(x => new {x.ClientId, x.Origin}); + corsOrigin.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired(); }); diff --git a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 2929fadae5..2730ae5e5b 100644 --- a/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -49,14 +49,8 @@ namespace Volo.Abp.IdentityServer { ProtocolType = "TestProtocol-42" }; - - client42.AllowedCorsOrigins.Add( - new ClientCorsOrigin(_guidGenerator.Create()) - { - Origin = "Origin1", - ClientId = client42.Id - } - ); + + client42.AddCorsOrigin("Origin1"); client42.AddScope("api1");