2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2023-01-05 12:55:08 +00:00
|
|
|
using Elsa.Requirements;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2023-01-05 12:55:08 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Identity.Features;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides an authorization feature that configures the system with JWT bearer authentication.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DependsOn(typeof(IdentityFeature))]
|
|
|
|
|
public class DefaultAuthenticationFeature : FeatureBase
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public DefaultAuthenticationFeature(IModule module) : base(module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
|
|
|
|
var identityFeature = Module.Configure<IdentityFeature>();
|
2023-01-01 21:54:07 +00:00
|
|
|
var identityOptions = identityFeature.TokenOptions;
|
2022-12-30 12:11:29 +00:00
|
|
|
|
|
|
|
|
Services
|
|
|
|
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
|
|
|
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, identityOptions.ConfigureJwtBearerOptions);
|
2023-01-05 12:55:08 +00:00
|
|
|
|
|
|
|
|
Services.AddSingleton<IAuthorizationHandler, LocalHostRequirementHandler>();
|
|
|
|
|
Services.AddAuthorization(options => options.AddPolicy(IdentityPolicyNames.SecurityRoot, policy => policy.AddRequirements(new LocalHostRequirement()))); }
|
2022-12-30 12:11:29 +00:00
|
|
|
}
|