diff --git a/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs b/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs index c71301871a..d89d76bdc5 100644 --- a/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs +++ b/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs @@ -2,6 +2,6 @@ { public class ClientIdPRestrictionConsts { - public const int ProviderMaxLength = 200; + public const int ProviderMaxLength = 64; } } \ No newline at end of file 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 aabfb13dc8..13ae8d7f6c 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 @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using IdentityServer4; using IdentityServer4.Models; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; using Volo.Abp.Guids; @@ -101,8 +102,10 @@ namespace Volo.Abp.IdentityServer.Clients } - public Client(Guid id, string clientId) + public Client(Guid id, [NotNull] string clientId) { + Check.NotNull(clientId, nameof(clientId)); + Id = id; ClientId = clientId; @@ -136,7 +139,7 @@ namespace Volo.Abp.IdentityServer.Clients Properties = new List(); } - public virtual void AddGrantType(string grantType) + public virtual void AddGrantType([NotNull] string grantType) { AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); } @@ -150,29 +153,44 @@ namespace Volo.Abp.IdentityServer.Clients ); } - public virtual void AddSecret(string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) + public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) { ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description)); } - public virtual void AddScope(string scope) + public virtual void AddScope([NotNull] string scope) { AllowedScopes.Add(new ClientScope(Id, scope)); } - public virtual void AddCorsOrigin(string origin) + public virtual void AddCorsOrigin([NotNull] string origin) { AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); } - public virtual void AddRedirectUri(string redirectUri) + public virtual void AddRedirectUri([NotNull] string redirectUri) { RedirectUris.Add(new ClientRedirectUri(Id, redirectUri)); } - public virtual void AddPostLogoutRedirectUri(string postLogoutRedirectUri) + public virtual void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri) { PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); } + + public virtual void AddIdentityProviderRestriction([NotNull] string provider) + { + IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + } + + public virtual void AddProperty([NotNull] string key) + { + Properties.Add(new ClientProperty(Id, key)); + } + + public virtual void AddClaim(IGuidGenerator guidGenerator, [NotNull] string type, string value) + { + Claims.Add(new ClientClaim(guidGenerator.Create(), Id, type, value)); + } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs index ef1330d412..29b44a40f7 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs @@ -1,24 +1,30 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { public class ClientClaim : Entity { + public virtual Guid ClientId { get; set; } + public virtual string Type { get; set; } public virtual string Value { get; set; } - public virtual Guid ClientId { get; set; } - protected ClientClaim() { } - public ClientClaim(Guid id) + protected internal ClientClaim(Guid id, Guid clientId, [NotNull] string type, string value) { + Check.NotNull(type, nameof(type)); + Id = id; + ClientId = clientId; + Type = type; + Value = value; } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs index 98ad17d6aa..8d6925244d 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs @@ -1,4 +1,5 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients @@ -14,8 +15,10 @@ namespace Volo.Abp.IdentityServer.Clients } - protected internal ClientGrantType(Guid clientId, string grantType) + protected internal ClientGrantType(Guid clientId, [NotNull] string grantType) { + Check.NotNull(grantType, nameof(grantType)); + ClientId = clientId; GrantType = grantType; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs index 9515d1fb88..d6207dca1b 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs @@ -1,22 +1,26 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientIdPRestriction : Entity + public class ClientIdPRestriction : Entity { - public virtual string Provider { get; set; } - public virtual Guid ClientId { get; set; } + public virtual string Provider { get; set; } + protected ClientIdPRestriction() { } - public ClientIdPRestriction(Guid id) + protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider) { - Id = id; + Check.NotNull(provider, nameof(provider)); + + ClientId = clientId; + Provider = provider; } } } \ 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 0c694da631..2a82643e5c 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 @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientPostLogoutRedirectUri : Entity + public class ClientPostLogoutRedirectUri : Entity { public virtual Guid ClientId { get; protected set; } diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs index da6174d366..cf70c4378e 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs @@ -1,24 +1,28 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientProperty : Entity + public class ClientProperty : Entity { + public virtual Guid ClientId { get; set; } + public virtual string Key { get; set; } public virtual string Value { get; set; } - public virtual Guid ClientId { get; set; } - protected ClientProperty() { } - public ClientProperty(Guid id) + protected internal ClientProperty(Guid clientId, [NotNull] string key) { - Id = id; + Check.NotNull(key, nameof(key)); + + ClientId = clientId; + Key = key; } } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs index c9dfd58512..62affd2858 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.IdentityServer.Clients } protected internal ClientSecret( - Guid clientId, + Guid clientId, [NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, 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 12eb717337..fa286cb056 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 @@ -144,6 +144,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { idPRestriction.ToTable(TablePrefix + "ClientIdPRestrictions"); + idPRestriction.HasKey(x => new {x.ClientId, x.Provider}); + idPRestriction.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); }); @@ -160,6 +162,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { property.ToTable(TablePrefix + "ClientProperties"); + property.HasKey(x => new {x.ClientId, x.Key}); + property.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired(); property.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); });