mirror of https://github.com/abpframework/abp.git
38 changed files with 889 additions and 20 deletions
@ -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>(); |
|||
} |
|||
} |
|||
} |
|||
@ -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>(); |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -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) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using AutoMapper; |
|||
|
|||
namespace Volo.Abp.IdentityServer.Clients |
|||
{ |
|||
public class ClientAutoMapperProfile : Profile |
|||
{ |
|||
public ClientAutoMapperProfile() |
|||
{ |
|||
CreateMap<Client, IdentityServer4.Models.Client>(); |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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…
Reference in new issue