Skip to content

Commit

Permalink
Created Abp.ZeroCore.IdentityServer4.EntityFrameworkCore package.
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed May 26, 2017
1 parent 04b0cb4 commit 3b52fc7
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 15 deletions.
9 changes: 8 additions & 1 deletion Abp.Zero.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{364398C2-9B6A-40B3-9845-23ABFB8D12AB}"
EndProject
Expand Down Expand Up @@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Abp.ZeroCore.SampleApp", "t
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Abp.ZeroCore.Tests", "test\Abp.ZeroCore.Tests\Abp.ZeroCore.Tests.csproj", "{72427FA6-BC94-42AA-B9AC-3CF2E257E41B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Abp.ZeroCore.IdentityServer4.EntityFrameworkCore", "src\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore.csproj", "{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -155,6 +157,10 @@ Global
{72427FA6-BC94-42AA-B9AC-3CF2E257E41B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72427FA6-BC94-42AA-B9AC-3CF2E257E41B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72427FA6-BC94-42AA-B9AC-3CF2E257E41B}.Release|Any CPU.Build.0 = Release|Any CPU
{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -186,5 +192,6 @@ Global
{4B03D73D-D453-4FCB-95C8-F23D1B300DE7} = {01532A9D-77F4-477E-A43E-0E7078E4E9DD}
{D1084B66-375B-433A-9742-FD4A703994E1} = {01532A9D-77F4-477E-A43E-0E7078E4E9DD}
{72427FA6-BC94-42AA-B9AC-3CF2E257E41B} = {01532A9D-77F4-477E-A43E-0E7078E4E9DD}
{F4A295A8-3FE6-4397-B3F5-0CFF9EC483E9} = {A6CB86B2-8C58-42D7-917A-F1DEB29C121A}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion nupkg/pack.ps1
Expand Up @@ -14,8 +14,9 @@ $projects = (
"Abp.Zero.EntityFrameworkCore",
"Abp.Zero.NHibernate",
"Abp.ZeroCore",
"Abp.ZeroCore.EntityFrameworkCore",
"Abp.ZeroCore.IdentityServer4",
"Abp.ZeroCore.EntityFrameworkCore"
"Abp.ZeroCore.IdentityServer4.EntityFrameworkCore",
)

# Rebuild solution
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using Abp.Domain.Uow;
using Abp.Domain.Uow;
using Abp.EntityFrameworkCore;
using Abp.Modules;
using Abp.MultiTenancy;
Expand Down
@@ -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>
@@ -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());
}
}
}
@@ -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;
}
}
}
@@ -0,0 +1,9 @@
using Microsoft.EntityFrameworkCore;

namespace Abp.IdentityServer4
{
public interface IAbpPersistedGrantDbContext
{
DbSet<PersistedGrantEntity> PersistedGrants { get; set; }
}
}
Expand Up @@ -19,10 +19,11 @@

<ItemGroup>
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="1.0.1" />
<PackageReference Include="Abp.AutoMapper" Version="2.1.0-beta2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Abp.ZeroCore\Abp.ZeroCore.csproj" />
</ItemGroup>

</Project>
@@ -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);
}
}
}
Expand Up @@ -5,11 +5,11 @@
namespace Abp.IdentityServer4
{
[DependsOn(typeof(AbpZeroCoreModule))]
public class AbpZeroIdentityServerModule : AbpModule
public class AbpZeroCoreIdentityServerModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(AbpZeroIdentityServerModule).GetAssembly());
IocManager.RegisterAssemblyByConvention(typeof(AbpZeroCoreIdentityServerModule).GetAssembly());
}
}
}
@@ -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; }
}
}
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Abp.ZeroCore.IdentityServer4\Abp.ZeroCore.IdentityServer4.csproj" />
<ProjectReference Include="..\Abp.ZeroCore.SampleApp\Abp.ZeroCore.SampleApp.csproj" />
<ProjectReference Include="..\..\src\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Abp.ZeroCore.Tests\Abp.ZeroCore.Tests.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,4 +21,8 @@
<PackageReference Include="NSubstitute" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>
@@ -1,12 +1,14 @@
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.ZeroCore.SampleApp;
using Abp.Zero;
using Abp.ZeroCore.SampleApp.Core;
using Abp.ZeroCore.SampleApp.EntityFramework;
using Castle.Windsor.MsDependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace Abp.IdentityServer4
{
[DependsOn(typeof(AbpZeroIdentityServerModule), typeof(AbpZeroCoreSampleAppModule))]
[DependsOn(typeof(AbpZeroCoreIdentityServerEntityFrameworkCoreModule), typeof(AbpZeroTestModule))]
public class AbpZeroIdentityServerTestModule : AbpModule
{
public override void PreInitialize()
Expand All @@ -15,6 +17,15 @@ public override void PreInitialize()

var services = new ServiceCollection();

services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddAbpPersistedGrants<SampleAppDbContext>()
.AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
.AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
.AddInMemoryClients(IdentityServerConfig.GetClients())
.AddAbpIdentityServer<User>()
.AddProfileService<AbpProfileService<User>>();

var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(
IocManager.IocContainer,
services
Expand Down
@@ -0,0 +1,13 @@
using Xunit;

namespace Abp.IdentityServer4
{
public class DependencyInjection_Tests: AbpZeroIdentityServerTestBase
{
[Fact]
public void Should_Inject_AbpPersistedGrantStore()
{
Resolve<AbpPersistedGrantStore>();
}
}
}
@@ -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" }
}
};
}
}
}
5 changes: 4 additions & 1 deletion test/Abp.ZeroCore.SampleApp/Abp.ZeroCore.SampleApp.csproj
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Abp.ZeroCore.EntityFrameworkCore\Abp.ZeroCore.EntityFrameworkCore.csproj" />
<PackageReference Include="Abp.AutoMapper" Version="2.1.0-beta2" />
<PackageReference Include="Castle.Windsor.MsDependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
Expand All @@ -17,5 +16,9 @@
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore\Abp.ZeroCore.IdentityServer4.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Abp.IdentityFramework;

namespace Abp.ZeroCore.SampleApp.Core
{
Expand Down

0 comments on commit 3b52fc7

Please sign in to comment.