Browse Source

#185 Created entities, dbcontext and a unit test for identityserver module.

pull/190/head
Halil İbrahim Kalkan 9 years ago
parent
commit
79b4b98b79
  1. 10
      Volo.Abp.sln
  2. 2
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs
  3. 0
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDefaultDbContextFactory.cs
  4. 7
      src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj
  5. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs
  6. 13
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerModule.cs
  7. 33
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs
  8. 20
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs
  9. 35
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs
  10. 19
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs
  11. 20
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs
  12. 109
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs
  13. 12
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs
  14. 24
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs
  15. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs
  16. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs
  17. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs
  18. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs
  19. 24
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs
  20. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs
  21. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs
  22. 20
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs
  23. 25
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs
  24. 11
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs
  25. 32
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs
  26. 20
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs
  27. 35
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs
  28. 29
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs
  29. 22
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs
  30. 1
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj
  31. 32
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs
  32. 9
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs
  33. 28
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs
  34. 25
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Abp.IdentityServer.EntityFrameworkCore.Tests.csproj
  35. 12
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityApplicationTestBase.cs
  36. 36
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs
  37. 53
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs
  38. 37
      test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs

10
Volo.Abp.sln

@ -208,6 +208,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityServer.Dom
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.IdentityServer.EntityFrameworkCore", "src\Volo.Abp.IdentityServer.EntityFrameworkCore\Volo.Abp.IdentityServer.EntityFrameworkCore.csproj", "{8D891D68-7859-477D-BE78-99258B8B1E86}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Abp.IdentityServer", "Abp.IdentityServer", "{3DF5C4E8-51E7-4931-B4F4-EA390AB8FCC9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Abp.IdentityServer.EntityFrameworkCore.Tests", "test\Abp.IdentityServer.EntityFrameworkCore.Tests\Abp.IdentityServer.EntityFrameworkCore.Tests.csproj", "{0C73A439-7CD2-4105-8B70-30B896C15C72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -554,6 +558,10 @@ Global
{8D891D68-7859-477D-BE78-99258B8B1E86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D891D68-7859-477D-BE78-99258B8B1E86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D891D68-7859-477D-BE78-99258B8B1E86}.Release|Any CPU.Build.0 = Release|Any CPU
{0C73A439-7CD2-4105-8B70-30B896C15C72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C73A439-7CD2-4105-8B70-30B896C15C72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C73A439-7CD2-4105-8B70-30B896C15C72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C73A439-7CD2-4105-8B70-30B896C15C72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -654,6 +662,8 @@ Global
{324B920F-5BBA-46D8-BDC6-E1FA5EFE3733} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{210B1A21-CBC8-423D-9C69-3E63569F2C43} = {324B920F-5BBA-46D8-BDC6-E1FA5EFE3733}
{8D891D68-7859-477D-BE78-99258B8B1E86} = {324B920F-5BBA-46D8-BDC6-E1FA5EFE3733}
{3DF5C4E8-51E7-4931-B4F4-EA390AB8FCC9} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{0C73A439-7CD2-4105-8B70-30B896C15C72} = {3DF5C4E8-51E7-4931-B4F4-EA390AB8FCC9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

2
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs

@ -63,7 +63,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
base.OnModelCreating(builder);
//Split configuration to dedicated classes
//TODO: Split configuration to dedicated classes (probably a resuable extension method)
builder.Entity<IdentityUser>(b =>
{

0
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpDeskDefaultDbContextFactory.cs → src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDefaultDbContextFactory.cs

7
src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj

@ -14,6 +14,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\Volo.Abp.Ddd\Volo.Abp.Ddd.csproj" />
</ItemGroup>
@ -21,10 +22,4 @@
<PackageReference Include="IdentityServer4" Version="2.0.5" />
</ItemGroup>
<ItemGroup>
<Folder Include="Volo\Abp\IdentityServer\Clients\" />
<Folder Include="Volo\Abp\IdentityServer\ApiResources\" />
<Folder Include="Volo\Abp\IdentityServer\IdentityResources\" />
</ItemGroup>
</Project>

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

@ -0,0 +1,22 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer
{
[DependsOn(typeof(AbpAutoMapperModule))]
[DependsOn(typeof(AbpDddModule))]
public class AbpIdentityServerDomainModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<ClientAutoMapperProfile>(/*TODO: validate: true*/);
});
services.AddAssemblyOf<AbpIdentityServerDomainModule>();
}
}
}

13
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerModule.cs

@ -1,13 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer
{
public class AbpIdentityServerModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpIdentityServerModule>();
}
}
}

33
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResource : AggregateRoot
{
public virtual bool Enabled { get; set; } = true;
public virtual string Name { get; set; }
public virtual string DisplayName { get; set; }
public virtual string Description { get; set; }
public virtual List<ApiSecret> Secrets { get; set; }
public virtual List<ApiScope> Scopes { get; set; }
public virtual List<ApiResourceClaim> UserClaims { get; set; }
protected ApiResource()
{
}
public ApiResource(Guid id)
{
Id = id;
}
}
}

20
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs

@ -0,0 +1,20 @@
using System;
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResourceClaim : UserClaim
{
public virtual Guid ApiResourceId { get; set; }
protected ApiResourceClaim()
{
}
public ApiResourceClaim(Guid id)
: base(id)
{
}
}
}

35
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiScope : Entity
{
public virtual string Name { get; set; }
public virtual string DisplayName { get; set; }
public virtual string Description { get; set; }
public virtual bool Required { get; set; }
public virtual bool Emphasize { get; set; }
public virtual bool ShowInDiscoveryDocument { get; set; } = true;
public virtual List<ApiScopeClaim> UserClaims { get; set; }
public virtual Guid ApiResourceId { get; set; }
protected ApiScope()
{
}
public ApiScope(Guid id)
{
Id = id;
}
}
}

19
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs

@ -0,0 +1,19 @@
using System;
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiScopeClaim : UserClaim
{
public virtual Guid ApiScopeId { get; set; }
protected ApiScopeClaim()
{
}
protected ApiScopeClaim(Guid id)
: base(id)
{
}
}
}

20
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs

@ -0,0 +1,20 @@
using System;
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiSecret : Secret
{
public virtual string ApiResourceId { get; set; }
protected ApiSecret()
{
}
public ApiSecret(Guid id)
: base(id)
{
}
}
}

109
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using IdentityServer4;
using IdentityServer4.Models;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
//TODO: Move property initializations to ctor.
public class Client : AggregateRoot
{
public virtual string ClientId { get; set; }
public virtual string ClientName { get; set; }
public virtual string Description { get; set; }
public virtual string ClientUri { get; set; }
public virtual string LogoUri { get; set; }
public virtual bool Enabled { get; set; } = true;
public virtual string ProtocolType { get; set; } = IdentityServerConstants.ProtocolTypes.OpenIdConnect;
public virtual List<ClientSecret> ClientSecrets { get; set; }
public virtual bool RequireClientSecret { get; set; } = true;
public virtual bool RequireConsent { get; set; } = true;
public virtual bool AllowRememberConsent { get; set; } = true;
public virtual bool AlwaysIncludeUserClaimsInIdToken { get; set; }
public virtual List<ClientGrantType> AllowedGrantTypes { get; set; }
public virtual bool RequirePkce { get; set; }
public virtual bool AllowPlainTextPkce { get; set; }
public virtual bool AllowAccessTokensViaBrowser { get; set; }
public virtual List<ClientRedirectUri> RedirectUris { get; set; }
public virtual List<ClientPostLogoutRedirectUri> PostLogoutRedirectUris { get; set; }
public virtual string FrontChannelLogoutUri { get; set; }
public virtual bool FrontChannelLogoutSessionRequired { get; set; } = true;
public virtual string BackChannelLogoutUri { get; set; }
public virtual bool BackChannelLogoutSessionRequired { get; set; } = true;
public virtual bool AllowOfflineAccess { get; set; }
public virtual List<ClientScope> AllowedScopes { get; set; }
public virtual int IdentityTokenLifetime { get; set; } = 300;
public virtual int AccessTokenLifetime { get; set; } = 3600;
public virtual int AuthorizationCodeLifetime { get; set; } = 300;
public virtual int? ConsentLifetime { get; set; } = null;
public virtual int AbsoluteRefreshTokenLifetime { get; set; } = 2592000;
public virtual int SlidingRefreshTokenLifetime { get; set; } = 1296000;
public virtual int RefreshTokenUsage { get; set; } = (int)TokenUsage.OneTimeOnly;
public virtual bool UpdateAccessTokenClaimsOnRefresh { get; set; }
public virtual int RefreshTokenExpiration { get; set; } = (int)TokenExpiration.Absolute;
public virtual int AccessTokenType { get; set; } = (int)0; // AccessTokenType.Jwt;
public virtual bool EnableLocalLogin { get; set; } = true;
public virtual List<ClientIdPRestriction> IdentityProviderRestrictions { get; set; }
public virtual bool IncludeJwtId { get; set; }
public virtual List<ClientClaim> Claims { get; set; }
public virtual bool AlwaysSendClientClaims { get; set; }
public virtual string ClientClaimsPrefix { get; set; } = "client_";
public virtual string PairWiseSubjectSalt { get; set; }
public virtual List<ClientCorsOrigin> AllowedCorsOrigins { get; set; }
public virtual List<ClientProperty> Properties { get; set; }
protected Client()
{
}
public Client(Guid id)
{
Id = id;
}
}
}

12
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientAutoMapperProfile.cs

@ -0,0 +1,12 @@
using AutoMapper;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientAutoMapperProfile : Profile
{
public ClientAutoMapperProfile()
{
CreateMap<Client, IdentityServer4.Models.Client>();
}
}
}

24
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs

@ -0,0 +1,24 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientClaim : Entity
{
public virtual string Type { get; set; }
public virtual string Value { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientClaim()
{
}
public ClientClaim(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientCorsOrigin : Entity
{
public virtual string Origin { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientCorsOrigin()
{
}
public ClientCorsOrigin(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientGrantType : Entity
{
public virtual string GrantType { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientGrantType()
{
}
public ClientGrantType(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientIdPRestriction : Entity
{
public virtual string Provider { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientIdPRestriction()
{
}
public ClientIdPRestriction(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs

@ -0,0 +1,22 @@
using System;
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; set; }
protected ClientPostLogoutRedirectUri()
{
}
public ClientPostLogoutRedirectUri(Guid id)
{
Id = id;
}
}
}

24
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs

@ -0,0 +1,24 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientProperty : Entity
{
public virtual string Key { get; set; }
public virtual string Value { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientProperty()
{
}
public ClientProperty(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientRedirectUri : Entity
{
public virtual string RedirectUri { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientRedirectUri()
{
}
public ClientRedirectUri(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientScope : Entity
{
public virtual string Scope { get; set; }
public virtual Guid ClientId { get; set; }
protected ClientScope()
{
}
public ClientScope(Guid id)
{
Id = id;
}
}
}

20
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs

@ -0,0 +1,20 @@
using System;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientSecret : Secret
{
public virtual Guid ClientId { get; set; }
protected ClientSecret()
{
}
public ClientSecret(Guid id)
: base(id)
{
Id = id;
}
}
}

25
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs

@ -0,0 +1,25 @@
using System.Threading.Tasks;
using IdentityServer4.Stores;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientStore : IClientStore, ITransientDependency
{
private readonly IClientRepository _clientRepository;
private readonly IObjectMapper _objectMapper;
public ClientStore(IClientRepository clientRepository, IObjectMapper objectMapper)
{
_clientRepository = clientRepository;
_objectMapper = objectMapper;
}
public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
{
var client = await _clientRepository.FindByCliendIdIncludingAllAsync(clientId);
return _objectMapper.Map<Client, IdentityServer4.Models.Client>(client);
}
}
}

11
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs

@ -0,0 +1,11 @@
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.IdentityServer.Clients
{
public interface IClientRepository : IRepository<Client>
{
Task<Client> FindByCliendIdIncludingAllAsync([NotNull] string clientId);
}
}

32
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs

@ -0,0 +1,32 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.Grants
{
public class PersistedGrant : AggregateRoot
{
public virtual string Key { get; set; }
public virtual string Type { get; set; }
public virtual string SubjectId { get; set; }
public virtual string ClientId { get; set; }
public virtual DateTime CreationTime { get; set; }
public virtual DateTime? Expiration { get; set; }
public virtual string Data { get; set; }
protected PersistedGrant()
{
}
public PersistedGrant(Guid id)
{
Id = id;
}
}
}

20
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs

@ -0,0 +1,20 @@
using System;
namespace Volo.Abp.IdentityServer.IdentityResources
{
public class IdentityClaim : UserClaim
{
public virtual Guid IdentityResourceId { get; set; }
protected IdentityClaim()
{
}
public IdentityClaim(Guid id)
: base(id)
{
}
}
}

35
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.IdentityResources
{
public class IdentityResource : AggregateRoot
{
public virtual bool Enabled { get; set; } = true;
public virtual string Name { get; set; }
public virtual string DisplayName { get; set; }
public virtual string Description { get; set; }
public virtual bool Required { get; set; }
public virtual bool Emphasize { get; set; }
public virtual bool ShowInDiscoveryDocument { get; set; } = true;
public virtual List<IdentityClaim> UserClaims { get; set; } //TODO: Rename to Claims..?
protected IdentityResource()
{
}
public IdentityResource(Guid id)
{
Id = id;
}
}
}

29
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs

@ -0,0 +1,29 @@
using System;
using IdentityServer4;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer
{
//TODO: Eleminate Secret class for simplicity.
public abstract class Secret : Entity
{
public virtual string Description { get; set; }
public virtual string Value { get; set; }
public virtual DateTime? Expiration { get; set; }
public virtual string Type { get; set; } = IdentityServerConstants.SecretTypes.SharedSecret;
protected Secret()
{
}
protected Secret(Guid id)
{
Id = id;
}
}
}

22
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs

@ -0,0 +1,22 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer
{
//TODO: Eleminate UserClaim class for simplicity.
public abstract class UserClaim : Entity
{
public virtual string Type { get; set; }
protected UserClaim()
{
}
protected UserClaim(Guid id)
{
Id = id;
}
}
}

1
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj

@ -14,6 +14,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" />
</ItemGroup>

32
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ClientRepository.cs

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
namespace Volo.Abp.IdentityServer
{
public class ClientRepository : EfCoreRepository<IdentityServerDbContext, Client>, IClientRepository
{
public ClientRepository(IDbContextProvider<IdentityServerDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public Task<Client> FindByCliendIdIncludingAllAsync(string clientId)
{
return DbSet
.Include(x => x.AllowedGrantTypes)
.Include(x => x.RedirectUris)
.Include(x => x.PostLogoutRedirectUris)
.Include(x => x.AllowedScopes)
.Include(x => x.ClientSecrets)
.Include(x => x.Claims)
.Include(x => x.IdentityProviderRestrictions)
.Include(x => x.AllowedCorsOrigins)
.Include(x => x.Properties)
.FirstOrDefaultAsync(x => x.ClientId == clientId);
}
}
}

9
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerModule.cs

@ -1,12 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{
[DependsOn(typeof(AbpIdentityServerDomainModule))]
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
public class AbpIdentityServerEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAbpDbContext<IdentityServerDbContext>(options =>
{
options.WithDefaultRepositories();
//options.WithCustomRepository<IdentityUser, EfCoreIdentityUserRepository>();
});
services.AddAssemblyOf<AbpIdentityServerEntityFrameworkCoreModule>();
}
}

28
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.IdentityServer.IdentityResources;
namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{
public class IdentityServerDbContext : AbpDbContext<IdentityServerDbContext>
{
public DbSet<Client> Clients { get; set; }
public DbSet<PersistedGrant> PersistedGrants { get; set; }
public DbSet<ApiResource> ApiResources { get; set; }
public DbSet<IdentityResource> IdentityResources { get; set; }
//TODO: Add child entity types too...
public IdentityServerDbContext(DbContextOptions<IdentityServerDbContext> options)
: base(options)
{
}
}
}

25
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Abp.IdentityServer.EntityFrameworkCore.Tests.csproj

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Abp.IdentityServer.EntityFrameworkCore.Tests</AssemblyName>
<PackageId>Abp.IdentityServer.EntityFrameworkCore.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.EntityFrameworkCore\Volo.Abp.IdentityServer.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.0" />
</ItemGroup>
</Project>

12
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityApplicationTestBase.cs

@ -0,0 +1,12 @@
using Volo.Abp.TestBase;
namespace Volo.Abp.IdentityServer
{
public class AbpIdentityServerTestBase : AbpIntegratedTest<AbpIdentityServerTestEntityFrameworkCoreModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

36
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs

@ -0,0 +1,36 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.IdentityServer.Clients;
namespace Volo.Abp.IdentityServer
{
public class AbpIdentityServerTestDataBuilder : ITransientDependency
{
private readonly IClientRepository _clientRepository;
private readonly IGuidGenerator _guidGenerator;
public AbpIdentityServerTestDataBuilder(
IClientRepository clientRepository,
IGuidGenerator guidGenerator)
{
_clientRepository = clientRepository;
_guidGenerator = guidGenerator;
}
public void Build()
{
AddClients();
}
private void AddClients()
{
var client42 = new Client(_guidGenerator.Create())
{
ClientId = "42",
ProtocolType = "TestProtocol-42"
};
_clientRepository.Insert(client42);
}
}
}

53
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs

@ -0,0 +1,53 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
namespace Volo.Abp.IdentityServer
{
[DependsOn(typeof(AbpAutofacModule))]
[DependsOn(typeof(AbpIdentityServerEntityFrameworkCoreModule))]
public class AbpIdentityServerTestEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpIdentityServerTestEntityFrameworkCoreModule>();
services.AddEntityFrameworkInMemoryDatabase();
var databaseName = Guid.NewGuid().ToString();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseInMemoryDatabase(databaseName);
});
});
services.Configure<UnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService<AbpIdentityServerTestDataBuilder>()
.Build();
}
}
}
}

37
test/Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs

@ -0,0 +1,37 @@
using System.Threading.Tasks;
using IdentityServer4.Stores;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
namespace Volo.Abp.IdentityServer.Clients
{
public class ClientStore_Tests : AbpIdentityServerTestBase
{
private readonly IClientStore _clientStore;
public ClientStore_Tests()
{
_clientStore = ServiceProvider.GetRequiredService<IClientStore>();
}
[Fact]
public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found()
{
var client = await _clientStore.FindClientByIdAsync("non-existing-id");
client.ShouldBeNull();
}
[Fact]
public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found()
{
//Act
var client = await _clientStore.FindClientByIdAsync("42");
//Assert
client.ShouldNotBeNull();
client.ClientId.ShouldBe("42");
client.ProtocolType.ShouldBe("TestProtocol-42");
}
}
}
Loading…
Cancel
Save