* Refactor identity options * Delete templates Will be created as part of a separate repo. * Little cleanup * Increase token lifetime for reference server app * Cleanup workflow definition editor plugin * Fix workflow instance viewer component * Update identity generator to use hyphen format * Improve workflow and activity execution pipeline registration API * Fix workflow journal * Update backend * Prevent unnecessary re-render * Restore autolayout function
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using Elsa.Common.Features;
|
|
using Elsa.Extensions;
|
|
using Elsa.Features.Abstractions;
|
|
using Elsa.Features.Attributes;
|
|
using Elsa.Features.Services;
|
|
using Elsa.Identity.Entities;
|
|
using Elsa.Identity.HostedServices;
|
|
using Elsa.Identity.Implementations;
|
|
using Elsa.Identity.Options;
|
|
using Elsa.Identity.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Elsa.Identity.Features;
|
|
|
|
/// <summary>
|
|
/// Provides identity feature to authenticate & authorize API requests.
|
|
/// </summary>
|
|
[DependsOn(typeof(SystemClockFeature))]
|
|
public class IdentityFeature : FeatureBase
|
|
{
|
|
/// <inheritdoc />
|
|
public IdentityFeature(IModule module) : base(module)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// A delegate to configure <see cref="Options.IdentityOptions"/>.
|
|
/// </summary>
|
|
public IdentityOptions IdentityOptions { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// A delegate to configure <see cref="Options.IdentityTokenOptions"/>.
|
|
/// </summary>
|
|
public IdentityTokenOptions TokenOptions { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// A delegate that creates an instance of an implementation of <see cref="IUserStore"/>.
|
|
/// </summary>
|
|
public Func<IServiceProvider, IUserStore> UserStore { get; set; } = sp => sp.GetRequiredService<MemoryUserStore>();
|
|
|
|
/// <summary>
|
|
/// A delegate that creates an instance of an implementation of <see cref="IRoleStore"/>.
|
|
/// </summary>
|
|
public Func<IServiceProvider, IRoleStore> RoleStore { get; set; } = sp => sp.GetRequiredService<MemoryRoleStore>();
|
|
|
|
/// <inheritdoc />
|
|
public override void Configure()
|
|
{
|
|
Module.AddFastEndpointsAssembly(GetType());
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void ConfigureHostedServices()
|
|
{
|
|
if(IdentityOptions.CreateDefaultAdmin)
|
|
Module.ConfigureHostedService<SetupDefaultUserHostedService>();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Apply()
|
|
{
|
|
Services.Configure<IdentityTokenOptions>(options => options.CopyFrom(TokenOptions));
|
|
|
|
Services
|
|
.AddMemoryStore<User, MemoryUserStore>()
|
|
.AddMemoryStore<Role, MemoryRoleStore>()
|
|
.AddSingleton(UserStore)
|
|
.AddSingleton(RoleStore)
|
|
.AddSingleton<IPasswordHasher, DefaultPasswordHasher>()
|
|
.AddSingleton<IAccessTokenIssuer, DefaultAccessTokenIssuer>()
|
|
.AddSingleton<ICredentialsValidator, DefaultCredentialsValidator>()
|
|
;
|
|
}
|
|
} |