2022-11-23 10:20:00 +00:00
|
|
|
using Elsa.Features.Services;
|
|
|
|
|
using Elsa.Identity.Features;
|
|
|
|
|
|
2022-12-31 15:16:43 +00:00
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
|
namespace Elsa.Extensions;
|
2022-11-23 10:20:00 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extensions for <see cref="IModule"/> that installs the <see cref="IdentityFeature"/> feature.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class ModuleExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installs & configures the <see cref="IdentityFeature"/> feature.
|
|
|
|
|
/// </summary>
|
2022-12-30 12:11:29 +00:00
|
|
|
public static IModule UseIdentity(this IModule module, Action<IdentityFeature> configure)
|
|
|
|
|
{
|
|
|
|
|
module.Configure(configure);
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installs & configures the <see cref="IdentityFeature"/> feature.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IModule UseIdentity(this IModule module, string signingKey, string issuer = "http://elsa.api", string audience = "http://elsa.api", TimeSpan? tokenLifetime = default)
|
|
|
|
|
{
|
2023-03-26 21:53:17 +00:00
|
|
|
module.UseIdentity(identity => identity.TokenOptions = options =>
|
2022-12-30 12:11:29 +00:00
|
|
|
{
|
2023-03-26 21:53:17 +00:00
|
|
|
options.Audience = audience;
|
|
|
|
|
options.Issuer = issuer;
|
|
|
|
|
options.AccessTokenLifetime = tokenLifetime ?? TimeSpan.FromHours(1);
|
|
|
|
|
options.SigningKey = signingKey;
|
2022-12-30 12:11:29 +00:00
|
|
|
});
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Installs & configures the <see cref="IdentityFeature"/> feature.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IModule UseDefaultAuthentication(this IModule module, Action<DefaultAuthenticationFeature>? configure = default)
|
2022-11-23 10:20:00 +00:00
|
|
|
{
|
|
|
|
|
module.Configure(configure);
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
}
|