Browse Source

Introduce `AddIdentityServerCookieAuthentication` to `AbpIdentityServerBuilderOptions`.

pull/13662/head
maliming 4 years ago
parent
commit
2a7ee83a50
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs
  2. 40
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

6
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs

@ -27,4 +27,10 @@ public class AbpIdentityServerBuilderOptions
/// Set false to suppress AddDeveloperSigningCredential() call on the IIdentityServerBuilder.
/// </summary>
public bool AddDeveloperSigningCredential { get; set; } = true;
/// <summary>
/// Adds the default cookie handlers and corresponding configuration
/// Default: true, Set false to suppress AddCookieAuthentication() call on the IIdentityServerBuilder.
/// </summary>
public bool AddIdentityServerCookieAuthentication { get; set; } = true;
}

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

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using IdentityServer4.Configuration;
using IdentityServer4.Services;
using IdentityServer4.Stores;
using Microsoft.Extensions.DependencyInjection;
@ -71,13 +72,7 @@ public class AbpIdentityServerDomainModule : AbpModule
var configuration = services.GetConfiguration();
var builderOptions = services.ExecutePreConfiguredActions<AbpIdentityServerBuilderOptions>();
var identityServerBuilder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
});
var identityServerBuilder = AddIdentityServer(services, builderOptions);
if (builderOptions.AddDeveloperSigningCredential)
{
@ -110,6 +105,37 @@ public class AbpIdentityServerDomainModule : AbpModule
}
}
private static IIdentityServerBuilder AddIdentityServer(IServiceCollection services, AbpIdentityServerBuilderOptions abpIdentityServerBuilderOptions)
{
services.Configure<IdentityServerOptions>(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
});
var identityServerBuilder = services.AddIdentityServerBuilder()
.AddRequiredPlatformServices()
.AddCoreServices()
.AddDefaultEndpoints()
.AddPluggableServices()
.AddValidators()
.AddResponseGenerators()
.AddDefaultSecretParsers()
.AddDefaultSecretValidators();
if (abpIdentityServerBuilderOptions.AddIdentityServerCookieAuthentication)
{
identityServerBuilder.AddCookieAuthentication();
}
// provide default in-memory implementation, not suitable for most production scenarios
identityServerBuilder.AddInMemoryPersistedGrants();
return identityServerBuilder;
}
public override void PostConfigureServices(ServiceConfigurationContext context)
{
OneTimeRunner.Run(() =>

Loading…
Cancel
Save