Browse Source

Resolved #757: IdentityServer module should work with inmemory stores if data access layer is not added

pull/765/head
Halil ibrahim Kalkan 8 years ago
parent
commit
000b619c56
  1. 19
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs
  2. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs
  3. 41
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs
  4. 1
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs
  5. 3
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs
  6. 19
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs
  7. 16
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs
  8. 10
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs
  9. 7
      modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs
  10. 1
      modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo.Abp.IdentityServer.TestBase.csproj
  11. 4
      modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs

19
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs

@ -13,16 +13,21 @@ namespace Volo.Abp.IdentityServer
public static class AbpIdentityServerBuilderExtensions
{
public static IIdentityServerBuilder AddAbpIdentityServer(
this IIdentityServerBuilder builder,
Action<AbpIdentityServerOptions> optionsAction = null)
this IIdentityServerBuilder builder,
AbpIdentityServerBuilderOptions options = null)
{
var options = new AbpIdentityServerOptions();
optionsAction?.Invoke(options);
if (options == null)
{
options = new AbpIdentityServerBuilderOptions();
}
//TODO: AspNet Identity integration lines. Can be extracted to a extension method
builder.AddAspNetIdentity<IdentityUser>();
builder.AddProfileService<AbpProfileService>();
builder.AddResourceOwnerValidator<AbpResourceOwnerPasswordValidator>();
if (options.IntegrateToAspNetIdentity)
{
builder.AddAspNetIdentity<IdentityUser>();
builder.AddProfileService<AbpProfileService>();
builder.AddResourceOwnerValidator<AbpResourceOwnerPasswordValidator>();
}
builder.Services.Replace(ServiceDescriptor.Transient<IClaimsService, AbpClaimsService>());

11
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerOptions.cs → modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs

@ -1,6 +1,9 @@
using System.IdentityModel.Tokens.Jwt;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.IdentityServer
{
public class AbpIdentityServerOptions
public class AbpIdentityServerBuilderOptions
{
/// <summary>
/// Updates <see cref="JwtSecurityTokenHandler.DefaultInboundClaimTypeMap"/> to be compatible with identity server claims.
@ -13,5 +16,11 @@ namespace Volo.Abp.IdentityServer
/// Default: true.
/// </summary>
public bool UpdateAbpClaimTypes { get; set; } = true;
/// <summary>
/// Integrate to AspNet Identity.
/// Default: true.
/// </summary>
public bool IntegrateToAspNetIdentity { get; set; } = true;
}
}

41
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using IdentityServer4.Services;
using IdentityServer4.Stores;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Domain;
using Volo.Abp.Identity;
@ -8,11 +10,13 @@ using Volo.Abp.Security;
namespace Volo.Abp.IdentityServer
{
[DependsOn(typeof(AbpIdentityServerDomainSharedModule))]
[DependsOn(typeof(AbpDddDomainModule))]
[DependsOn(typeof(AbpAutoMapperModule))]
[DependsOn(typeof(AbpIdentityDomainModule))]
[DependsOn(typeof(AbpSecurityModule))]
[DependsOn(
typeof(AbpIdentityServerDomainSharedModule),
typeof(AbpDddDomainModule),
typeof(AbpAutoMapperModule),
typeof(AbpIdentityDomainModule),
typeof(AbpSecurityModule)
)]
public class AbpIdentityServerDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -24,9 +28,12 @@ namespace Volo.Abp.IdentityServer
AddIdentityServer(context.Services);
}
private static void AddIdentityServer(IServiceCollection services)
{
var configuration = services.GetConfiguration();
var builderOptions = services.ExecutePreConfiguredActions<AbpIdentityServerBuilderOptions>();
var identityServerBuilder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
@ -37,11 +44,25 @@ namespace Volo.Abp.IdentityServer
identityServerBuilder
.AddDeveloperSigningCredential() //TODO: Should be able to change this!
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>()
.AddAbpIdentityServer();
.AddAbpIdentityServer(builderOptions);
services.ExecutePreConfiguredActions(identityServerBuilder);
if (!services.IsAdded<IPersistedGrantService>())
{
identityServerBuilder.AddInMemoryPersistedGrants();
}
if (!services.IsAdded<IClientStore>())
{
identityServerBuilder.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"));
}
if (!services.IsAdded<IResourceStore>())
{
identityServerBuilder.AddInMemoryApiResources(configuration.GetSection("IdentityServer:ApiResources"));
identityServerBuilder.AddInMemoryIdentityResources(configuration.GetSection("IdentityServer:IdentityResources"));
}
}
}
}

1
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs

@ -12,6 +12,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
public class AbpProfileService : ProfileService<IdentityUser>
{
private readonly ICurrentTenant _currentTenant;
public AbpProfileService(
IdentityUserManager userManager,
IUserClaimsPrincipalFactory<IdentityUser> claimsFactory,

3
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs

@ -2,13 +2,12 @@
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Stores;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.IdentityServer.Grants
{
public class PersistedGrantStore : IPersistedGrantStore, ITransientDependency
public class PersistedGrantStore : IPersistedGrantStore
{
private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly IObjectMapper _objectMapper;

19
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs

@ -0,0 +1,19 @@
using IdentityServer4.Stores;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants;
namespace Volo.Abp.IdentityServer
{
public static class IdentityServerBuilderExtensions
{
public static IIdentityServerBuilder AddAbpStores(this IIdentityServerBuilder builder)
{
builder.Services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
return builder
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>();
}
}
}

16
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs

@ -8,10 +8,22 @@ using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{
[DependsOn(typeof(AbpIdentityServerDomainModule))]
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
[DependsOn(
typeof(AbpIdentityServerDomainModule),
typeof(AbpEntityFrameworkCoreModule)
)]
public class AbpIdentityServerEntityFrameworkCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.PreConfigure<IIdentityServerBuilder>(
builder =>
{
builder.AddAbpStores();
}
);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<IdentityServerDbContext>(options =>

10
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs

@ -14,6 +14,16 @@ namespace Volo.Abp.IdentityServer.MongoDB
)]
public class AbpIdentityServerMongoDbModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.PreConfigure<IIdentityServerBuilder>(
builder =>
{
builder.AddAbpStores();
}
);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddMongoDbContext<AbpIdentityServerMongoDbContext>(options =>

7
modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Modularity;
using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer
{

1
modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo.Abp.IdentityServer.TestBase.csproj

@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" />
</ItemGroup>

4
modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs

@ -1,7 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.IdentityServer
{
@ -26,9 +25,6 @@ namespace Volo.Abp.IdentityServer
{
using (var scope = context.ServiceProvider.CreateScope())
{
//var dataSeeder = scope.ServiceProvider.GetRequiredService<IIdentityServerDataSeeder>();
//AsyncHelper.RunSync(() => dataSeeder.SeedAsync("1q2w3E*"));
scope.ServiceProvider
.GetRequiredService<AbpIdentityServerTestDataBuilder>()
.Build();

Loading…
Cancel
Save