| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Options; |
| | | 3 | | using Elsa.ExternalAuthentication.Permissions; |
| | | 4 | | using Elsa.ExternalAuthentication.Policies; |
| | | 5 | | using Elsa.ExternalAuthentication.Providers; |
| | | 6 | | using Elsa.ExternalAuthentication.Services; |
| | | 7 | | using Elsa.ExternalAuthentication.Stores.InMemory; |
| | | 8 | | using Elsa.ExternalAuthentication.Validation; |
| | | 9 | | using Elsa.Identity.Contracts; |
| | | 10 | | using Microsoft.AspNetCore.Builder; |
| | | 11 | | using Microsoft.AspNetCore.DataProtection; |
| | | 12 | | using Microsoft.AspNetCore.RateLimiting; |
| | | 13 | | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| | | 14 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 15 | | using Microsoft.Extensions.Options; |
| | | 16 | | |
| | | 17 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 18 | | |
| | | 19 | | public static class ServiceCollectionExtensions |
| | | 20 | | { |
| | | 21 | | /// <summary>Adds the explicit, non-readiness External Authentication health bridge.</summary> |
| | | 22 | | public static IHealthChecksBuilder AddExternalAuthenticationHealthCheck(this IServiceCollection services, string nam |
| | 0 | 23 | | services.AddHealthChecks().AddCheck<ExternalAuthenticationHealthCheck>(name, HealthStatus.Degraded, tags ?? ["ex |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Adds the protocol-neutral External Authentication foundation and its single-node defaults. |
| | | 27 | | /// Hosts requiring durable, multi-node state may replace the store registrations. |
| | | 28 | | /// </summary> |
| | | 29 | | public static IServiceCollection AddExternalAuthenticationServices(this IServiceCollection services, Action<External |
| | | 30 | | { |
| | 5 | 31 | | var options = services.AddOptions<ExternalAuthenticationOptions>().ValidateOnStart(); |
| | 5 | 32 | | if (configureOptions != null) |
| | 2 | 33 | | options.Configure(configureOptions); |
| | | 34 | | |
| | 5 | 35 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, RejectUn |
| | 5 | 36 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, CreateUs |
| | 5 | 37 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, MatchExt |
| | 5 | 38 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ElsaRoleP |
| | 5 | 39 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ClaimMapp |
| | 5 | 40 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, GroupMapp |
| | 5 | 41 | | services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ClaimPass |
| | 5 | 42 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<ExternalAuthenticationOptions>, ExternalA |
| | 5 | 43 | | services.AddDataProtection(); |
| | 6 | 44 | | services.AddRateLimiter(_ => { }); |
| | 5 | 45 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<RateLimiterOptions>, ConfigureExternalAu |
| | | 46 | | |
| | 5 | 47 | | services.TryAddSingleton<ConnectionRevisionCalculator>(); |
| | 5 | 48 | | services.TryAddSingleton<FinalLoginPathGuard>(); |
| | 5 | 49 | | services.TryAddSingleton<ExternalAuthenticationSecurityNotifier>(); |
| | 5 | 50 | | services.TryAddScoped<ConnectionTestService>(); |
| | 5 | 51 | | services.TryAddScoped<PreviewSignInService>(); |
| | 5 | 52 | | services.TryAddSingleton<ExternalAuthenticationHealthCheck>(); |
| | 5 | 53 | | services.TryAddSingleton<IOutboundDnsResolver, SystemOutboundDnsResolver>(); |
| | 5 | 54 | | services.TryAddSingleton<OutboundDestinationValidator>(); |
| | 5 | 55 | | services.TryAddSingleton<IValidatedAddressConnector, SocketValidatedAddressConnector>(); |
| | 5 | 56 | | services.TryAddSingleton<ValidatedOutboundConnectionFactory>(); |
| | 5 | 57 | | services.TryAddSingleton<IProviderHttpClientFactory, ProviderHttpClientFactory>(); |
| | 5 | 58 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IIdentityProviderConnectionSource, ConfigurationIdentityPr |
| | 5 | 59 | | services.TryAddSingleton<IIdentityProviderConnectionStore, InMemoryIdentityProviderConnectionStore>(); |
| | 5 | 60 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IIdentityProviderConnectionSource, DatabaseIdentityProvide |
| | 5 | 61 | | services.TryAddSingleton<IIdentityProviderConnectionRegistry, DefaultIdentityProviderConnectionRegistry>(); |
| | 5 | 62 | | services.TryAddSingleton<IIdentityProviderConnectionValidityAssessor, IdentityProviderConnectionValidityAssessor |
| | 5 | 63 | | services.TryAddSingleton<ExtensionDescriptorValidator>(); |
| | 5 | 64 | | services.TryAddSingleton<IExternalAuthenticationAdapterRegistry, DefaultExternalAuthenticationAdapterRegistry>() |
| | 5 | 65 | | services.TryAddSingleton<IUnlinkedIdentityPolicyRegistry, DefaultUnlinkedIdentityPolicyRegistry>(); |
| | 5 | 66 | | services.TryAddSingleton<IExternalUserMatcherRegistry, DefaultExternalUserMatcherRegistry>(); |
| | 5 | 67 | | services.TryAddScoped<IPermissionGrantSourceRegistry, DefaultPermissionGrantSourceRegistry>(); |
| | 5 | 68 | | services.TryAddSingleton<IAdapterSettingsMigrationService, AdapterSettingsMigrationService>(); |
| | | 69 | | |
| | 5 | 70 | | services.TryAddSingleton<IExternalAuthenticationStateStore, InMemoryExternalAuthenticationStateStore>(); |
| | 5 | 71 | | services.TryAddSingleton<IExternalAuthenticationHandleHasher, HmacExternalAuthenticationHandleHasher>(); |
| | 5 | 72 | | services.TryAddSingleton<IAuthorizationGrantStore, InMemoryAuthorizationGrantStore>(); |
| | 5 | 73 | | services.TryAddSingleton<IExternalAuthenticationSessionStore, InMemoryExternalAuthenticationSessionStore>(); |
| | 5 | 74 | | services.TryAddSingleton<IPreviewResultStore, InMemoryPreviewResultStore>(); |
| | 5 | 75 | | services.TryAddSingleton<IConnectionObservationStore, InMemoryConnectionObservationStore>(); |
| | 5 | 76 | | services.TryAddSingleton<IConnectionRegistryVersionStore, InMemoryConnectionRegistryVersionStore>(); |
| | 5 | 77 | | services.TryAddSingleton<InMemoryExternalIdentityProvisionerState>(); |
| | 5 | 78 | | services.TryAddScoped<InMemoryExternalIdentityProvisioner>(); |
| | 5 | 79 | | services.TryAddScoped<IExternalIdentityProvisioner>(serviceProvider => serviceProvider.GetRequiredService<InMemo |
| | 5 | 80 | | services.TryAddScoped<IExternalIdentityLinkManagementStore>(serviceProvider => serviceProvider.GetRequiredServic |
| | 5 | 81 | | services.TryAddScoped<ExternalIdentityLinkManagementService>(); |
| | 5 | 82 | | services.TryAddScoped<IExternalIdentityResolver, DefaultExternalIdentityResolver>(); |
| | 5 | 83 | | services.TryAddScoped<IPermissionGrantResolver, DefaultPermissionGrantResolver>(); |
| | 5 | 84 | | services.TryAddScoped<IPermissionDelegationAuthorizer, DefaultPermissionDelegationAuthorizer>(); |
| | 5 | 85 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<ISecretBindingResolver, ConfigurationSecretBindingResolver |
| | 5 | 86 | | services.TryAddScoped<IPermissionDescriptorRegistry, DefaultPermissionDescriptorRegistry>(); |
| | 5 | 87 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, RejectUnlinkedIdentityPolicy>()); |
| | 5 | 88 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, CreateUserUnlinkedIdentityPolicy> |
| | 5 | 89 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, MatchExternalUserUnlinkedIdentity |
| | 5 | 90 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ElsaRolePermissionGrantSource>()); |
| | 5 | 91 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ClaimMappingPermissionGrantSource>()) |
| | 5 | 92 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, GroupMappingPermissionGrantSource>()) |
| | 5 | 93 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ClaimPassThroughPermissionGrantSource |
| | 5 | 94 | | services.TryAddScoped<IExternalAuthenticationTokenIssuer, DefaultExternalAuthenticationTokenIssuer>(); |
| | 5 | 95 | | services.TryAddScoped<IExternalAuthenticationBroker, ExternalAuthenticationBroker>(); |
| | 5 | 96 | | services.TryAddScoped<IdentityProviderConnectionManagementService>(); |
| | 5 | 97 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IRoleDeletionDependencyContributor, ExternalAuthenticationRol |
| | 5 | 98 | | services.TryAddEnumerable(ServiceDescriptor.Scoped<IUserDeletionDependencyContributor, ExternalAuthenticationUse |
| | 5 | 99 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IPermissionDescriptorProvider, ExternalAuthenticationPermi |
| | | 100 | | |
| | 5 | 101 | | return services; |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | /// <summary> |
| | | 105 | | /// Registers the stable identifier of a trusted deployment-installed extension |
| | | 106 | | /// for startup selection validation. |
| | | 107 | | /// </summary> |
| | | 108 | | public static IServiceCollection AddExternalAuthenticationExtension( |
| | | 109 | | this IServiceCollection services, |
| | | 110 | | ExternalAuthenticationExtensionKind kind, |
| | | 111 | | string type) |
| | | 112 | | { |
| | 38 | 113 | | ArgumentException.ThrowIfNullOrWhiteSpace(type); |
| | 38 | 114 | | services.Configure<ExternalAuthenticationExtensionOptions>(options => |
| | 45 | 115 | | options.Registrations.Add(new ExternalAuthenticationExtensionRegistration(kind, type))); |
| | 38 | 116 | | return services; |
| | | 117 | | } |
| | | 118 | | } |