< Summary

Information
Class: Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Extensions/ServiceCollectionExtensions.cs
Line coverage
98%
Covered lines: 71
Uncovered lines: 1
Coverable lines: 72
Total lines: 118
Line coverage: 98.6%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddExternalAuthenticationHealthCheck(...)0%620%
AddExternalAuthenticationServices(...)100%22100%
AddExternalAuthenticationExtension(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Extensions/ServiceCollectionExtensions.cs

#LineLine coverage
 1using Elsa.ExternalAuthentication.Contracts;
 2using Elsa.ExternalAuthentication.Options;
 3using Elsa.ExternalAuthentication.Permissions;
 4using Elsa.ExternalAuthentication.Policies;
 5using Elsa.ExternalAuthentication.Providers;
 6using Elsa.ExternalAuthentication.Services;
 7using Elsa.ExternalAuthentication.Stores.InMemory;
 8using Elsa.ExternalAuthentication.Validation;
 9using Elsa.Identity.Contracts;
 10using Microsoft.AspNetCore.Builder;
 11using Microsoft.AspNetCore.DataProtection;
 12using Microsoft.AspNetCore.RateLimiting;
 13using Microsoft.Extensions.Diagnostics.HealthChecks;
 14using Microsoft.Extensions.DependencyInjection.Extensions;
 15using Microsoft.Extensions.Options;
 16
 17namespace Microsoft.Extensions.DependencyInjection;
 18
 19public 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
 023        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    {
 531        var options = services.AddOptions<ExternalAuthenticationOptions>().ValidateOnStart();
 532        if (configureOptions != null)
 233            options.Configure(configureOptions);
 34
 535        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, RejectUn
 536        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, CreateUs
 537        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.UnlinkedIdentityPolicy, MatchExt
 538        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ElsaRoleP
 539        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ClaimMapp
 540        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, GroupMapp
 541        services.AddExternalAuthenticationExtension(ExternalAuthenticationExtensionKind.PermissionGrantSource, ClaimPass
 542        services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<ExternalAuthenticationOptions>, ExternalA
 543        services.AddDataProtection();
 644        services.AddRateLimiter(_ => { });
 545        services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<RateLimiterOptions>, ConfigureExternalAu
 46
 547        services.TryAddSingleton<ConnectionRevisionCalculator>();
 548        services.TryAddSingleton<FinalLoginPathGuard>();
 549        services.TryAddSingleton<ExternalAuthenticationSecurityNotifier>();
 550        services.TryAddScoped<ConnectionTestService>();
 551        services.TryAddScoped<PreviewSignInService>();
 552        services.TryAddSingleton<ExternalAuthenticationHealthCheck>();
 553        services.TryAddSingleton<IOutboundDnsResolver, SystemOutboundDnsResolver>();
 554        services.TryAddSingleton<OutboundDestinationValidator>();
 555        services.TryAddSingleton<IValidatedAddressConnector, SocketValidatedAddressConnector>();
 556        services.TryAddSingleton<ValidatedOutboundConnectionFactory>();
 557        services.TryAddSingleton<IProviderHttpClientFactory, ProviderHttpClientFactory>();
 558        services.TryAddEnumerable(ServiceDescriptor.Singleton<IIdentityProviderConnectionSource, ConfigurationIdentityPr
 559        services.TryAddSingleton<IIdentityProviderConnectionStore, InMemoryIdentityProviderConnectionStore>();
 560        services.TryAddEnumerable(ServiceDescriptor.Singleton<IIdentityProviderConnectionSource, DatabaseIdentityProvide
 561        services.TryAddSingleton<IIdentityProviderConnectionRegistry, DefaultIdentityProviderConnectionRegistry>();
 562        services.TryAddSingleton<IIdentityProviderConnectionValidityAssessor, IdentityProviderConnectionValidityAssessor
 563        services.TryAddSingleton<ExtensionDescriptorValidator>();
 564        services.TryAddSingleton<IExternalAuthenticationAdapterRegistry, DefaultExternalAuthenticationAdapterRegistry>()
 565        services.TryAddSingleton<IUnlinkedIdentityPolicyRegistry, DefaultUnlinkedIdentityPolicyRegistry>();
 566        services.TryAddSingleton<IExternalUserMatcherRegistry, DefaultExternalUserMatcherRegistry>();
 567        services.TryAddScoped<IPermissionGrantSourceRegistry, DefaultPermissionGrantSourceRegistry>();
 568        services.TryAddSingleton<IAdapterSettingsMigrationService, AdapterSettingsMigrationService>();
 69
 570        services.TryAddSingleton<IExternalAuthenticationStateStore, InMemoryExternalAuthenticationStateStore>();
 571        services.TryAddSingleton<IExternalAuthenticationHandleHasher, HmacExternalAuthenticationHandleHasher>();
 572        services.TryAddSingleton<IAuthorizationGrantStore, InMemoryAuthorizationGrantStore>();
 573        services.TryAddSingleton<IExternalAuthenticationSessionStore, InMemoryExternalAuthenticationSessionStore>();
 574        services.TryAddSingleton<IPreviewResultStore, InMemoryPreviewResultStore>();
 575        services.TryAddSingleton<IConnectionObservationStore, InMemoryConnectionObservationStore>();
 576        services.TryAddSingleton<IConnectionRegistryVersionStore, InMemoryConnectionRegistryVersionStore>();
 577        services.TryAddSingleton<InMemoryExternalIdentityProvisionerState>();
 578        services.TryAddScoped<InMemoryExternalIdentityProvisioner>();
 579        services.TryAddScoped<IExternalIdentityProvisioner>(serviceProvider => serviceProvider.GetRequiredService<InMemo
 580        services.TryAddScoped<IExternalIdentityLinkManagementStore>(serviceProvider => serviceProvider.GetRequiredServic
 581        services.TryAddScoped<ExternalIdentityLinkManagementService>();
 582        services.TryAddScoped<IExternalIdentityResolver, DefaultExternalIdentityResolver>();
 583        services.TryAddScoped<IPermissionGrantResolver, DefaultPermissionGrantResolver>();
 584        services.TryAddScoped<IPermissionDelegationAuthorizer, DefaultPermissionDelegationAuthorizer>();
 585        services.TryAddEnumerable(ServiceDescriptor.Singleton<ISecretBindingResolver, ConfigurationSecretBindingResolver
 586        services.TryAddScoped<IPermissionDescriptorRegistry, DefaultPermissionDescriptorRegistry>();
 587        services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, RejectUnlinkedIdentityPolicy>());
 588        services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, CreateUserUnlinkedIdentityPolicy>
 589        services.TryAddEnumerable(ServiceDescriptor.Singleton<IUnlinkedIdentityPolicy, MatchExternalUserUnlinkedIdentity
 590        services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ElsaRolePermissionGrantSource>());
 591        services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ClaimMappingPermissionGrantSource>())
 592        services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, GroupMappingPermissionGrantSource>())
 593        services.TryAddEnumerable(ServiceDescriptor.Scoped<IPermissionGrantSource, ClaimPassThroughPermissionGrantSource
 594        services.TryAddScoped<IExternalAuthenticationTokenIssuer, DefaultExternalAuthenticationTokenIssuer>();
 595        services.TryAddScoped<IExternalAuthenticationBroker, ExternalAuthenticationBroker>();
 596        services.TryAddScoped<IdentityProviderConnectionManagementService>();
 597        services.TryAddEnumerable(ServiceDescriptor.Scoped<IRoleDeletionDependencyContributor, ExternalAuthenticationRol
 598        services.TryAddEnumerable(ServiceDescriptor.Scoped<IUserDeletionDependencyContributor, ExternalAuthenticationUse
 599        services.TryAddEnumerable(ServiceDescriptor.Singleton<IPermissionDescriptorProvider, ExternalAuthenticationPermi
 100
 5101        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    {
 38113        ArgumentException.ThrowIfNullOrWhiteSpace(type);
 38114        services.Configure<ExternalAuthenticationExtensionOptions>(options =>
 45115            options.Registrations.Add(new ExternalAuthenticationExtensionRegistration(kind, type)));
 38116        return services;
 117    }
 118}