Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Abp.ZeroCore.IdentityServer4.EntityFrameworkCore package.
- Loading branch information
Showing
18 changed files
with
257 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...Core.EntityFrameworkCore/Zero/EntityFrameworkCore/AbpZeroCoreEntityFrameworkCoreModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...entityServer4.EntityFrameworkCore/Abp.ZeroCore.IdentityServer4.EntityFrameworkCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard1.6</TargetFrameworks> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<AssemblyName>Abp.ZeroCore.IdentityServer4.EntityFrameworkCore</AssemblyName> | ||
<PackageId>Abp.ZeroCore.IdentityServer4.EntityFrameworkCore</PackageId> | ||
<PackageTags>asp.net;asp.net mvc;boilerplate;application framework;web framework;framework;domain driven design;multitenancy;user management;role management;identity server;entity framework</PackageTags> | ||
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> | ||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> | ||
<RootNamespace>Abp</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Abp.ZeroCore.EntityFrameworkCore\Abp.ZeroCore.EntityFrameworkCore.csproj" /> | ||
<ProjectReference Include="..\Abp.ZeroCore.IdentityServer4\Abp.ZeroCore.IdentityServer4.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
...EntityFrameworkCore/IdentityServer4/AbpZeroCoreIdentityServerEntityFrameworkCoreModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Abp.Modules; | ||
using Abp.Reflection.Extensions; | ||
using Abp.Zero.EntityFrameworkCore; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
[DependsOn(typeof(AbpZeroCoreIdentityServerModule), typeof(AbpZeroCoreEntityFrameworkCoreModule))] | ||
public class AbpZeroCoreIdentityServerEntityFrameworkCoreModule : AbpModule | ||
{ | ||
public override void Initialize() | ||
{ | ||
IocManager.RegisterAssemblyByConvention(typeof(AbpZeroCoreIdentityServerEntityFrameworkCoreModule).GetAssembly()); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rameworkCore/IdentityServer4/AbpZeroIdentityServerBuilderEntityFrameworkCoreExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using IdentityServer4.Stores; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
public static class AbpZeroIdentityServerBuilderEntityFrameworkCoreExtensions | ||
{ | ||
public static IIdentityServerBuilder AddAbpPersistedGrants<TDbContext>(this IIdentityServerBuilder builder) | ||
where TDbContext : IAbpPersistedGrantDbContext | ||
{ | ||
builder.Services.AddTransient<IPersistedGrantStore, AbpPersistedGrantStore>(); | ||
return builder; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...roCore.IdentityServer4.EntityFrameworkCore/IdentityServer4/IAbpPersistedGrantDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
public interface IAbpPersistedGrantDbContext | ||
{ | ||
DbSet<PersistedGrantEntity> PersistedGrants { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Abp.ZeroCore.IdentityServer4/IdentityServer4/AbpPersistentGrantStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Abp.Domain.Repositories; | ||
using Abp.Domain.Uow; | ||
using IdentityServer4.Models; | ||
using IdentityServer4.Stores; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
public class AbpPersistedGrantStore : AbpServiceBase, IPersistedGrantStore | ||
{ | ||
private readonly IRepository<PersistedGrantEntity, long> _persistedGrantRepository; | ||
|
||
public AbpPersistedGrantStore(IRepository<PersistedGrantEntity, long> persistedGrantRepository) | ||
{ | ||
_persistedGrantRepository = persistedGrantRepository; | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task StoreAsync(PersistedGrant grant) | ||
{ | ||
var entity = await _persistedGrantRepository.FirstOrDefaultAsync(x => x.Key == grant.Key); | ||
if (entity == null) | ||
{ | ||
await _persistedGrantRepository.InsertAsync(ObjectMapper.Map<PersistedGrantEntity>(grant)); | ||
} | ||
else | ||
{ | ||
ObjectMapper.Map(grant, entity); | ||
} | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task<PersistedGrant> GetAsync(string key) | ||
{ | ||
var entity = await _persistedGrantRepository.FirstOrDefaultAsync(x => x.Key == key); | ||
if (entity == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return ObjectMapper.Map<PersistedGrant>(entity); | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId) | ||
{ | ||
var entities = await _persistedGrantRepository.GetAllListAsync(x => x.SubjectId == subjectId); | ||
return ObjectMapper.Map<List<PersistedGrant>>(entities); | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task RemoveAsync(string key) | ||
{ | ||
await _persistedGrantRepository.DeleteAsync(x => x.Key == key); | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task RemoveAllAsync(string subjectId, string clientId) | ||
{ | ||
await _persistedGrantRepository.DeleteAsync(x => x.SubjectId == subjectId && x.ClientId == clientId); | ||
} | ||
|
||
[UnitOfWork] | ||
public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type) | ||
{ | ||
await _persistedGrantRepository.DeleteAsync(x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Abp.ZeroCore.IdentityServer4/IdentityServer4/PersistedGrantEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Abp.AutoMapper; | ||
using Abp.Domain.Entities; | ||
using IdentityServer4.Models; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
[AutoMap(typeof(PersistedGrant))] | ||
public class PersistedGrantEntity : Entity<long> | ||
{ | ||
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/Abp.ZeroCore.IdentityServer4.Tests/IdentityServer4/DependencyInjection_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Xunit; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
public class DependencyInjection_Tests: AbpZeroIdentityServerTestBase | ||
{ | ||
[Fact] | ||
public void Should_Inject_AbpPersistedGrantStore() | ||
{ | ||
Resolve<AbpPersistedGrantStore>(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/Abp.ZeroCore.IdentityServer4.Tests/IdentityServer4/IdentityServerConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using IdentityServer4.Models; | ||
|
||
namespace Abp.IdentityServer4 | ||
{ | ||
public static class IdentityServerConfig | ||
{ | ||
public static IEnumerable<ApiResource> GetApiResources() | ||
{ | ||
return new List<ApiResource> | ||
{ | ||
new ApiResource("default-api", "Default (all) API") | ||
}; | ||
} | ||
|
||
public static IEnumerable<IdentityResource> GetIdentityResources() | ||
{ | ||
return new List<IdentityResource> | ||
{ | ||
new IdentityResources.OpenId(), | ||
new IdentityResources.Profile(), | ||
new IdentityResources.Email(), | ||
new IdentityResources.Phone() | ||
}; | ||
} | ||
|
||
public static IEnumerable<Client> GetClients() | ||
{ | ||
return new List<Client> | ||
{ | ||
new Client | ||
{ | ||
ClientId = "test-client", | ||
ClientName = "My Test Client", | ||
AllowedGrantTypes = new List<string>{ "hybrid", "client_credentials", "password" }, | ||
ClientSecrets = new List<Secret> {new Secret("secret".Sha256()) }, | ||
AllowedScopes = new List<string> { "default-api" } | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
test/Abp.ZeroCore.SampleApp/Core/ServicesCollectionDependencyRegistrar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.