< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.DiscoverLoginMethodsResponse
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/DiscoverLoginMethods.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 37
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Methods()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/DiscoverLoginMethods.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Multitenancy;
 3using Elsa.ExternalAuthentication.Constants;
 4using Elsa.ExternalAuthentication.Models;
 5using Elsa.ExternalAuthentication.Services;
 6using Microsoft.AspNetCore.Builder;
 7
 8namespace Elsa.ExternalAuthentication.Endpoints.Broker;
 9
 10internal sealed class DiscoverLoginMethods(IExternalAuthenticationBroker broker, ITenantAccessor tenantAccessor) : ElsaE
 11{
 12    public override void Configure()
 13    {
 14        Get("/external-authentication/login-methods");
 15        AllowAnonymous();
 16        Options(x => x.RequireRateLimiting(ExternalAuthenticationRateLimitPolicyNames.Discovery));
 17    }
 18
 19    public override async Task<DiscoverLoginMethodsResponse> ExecuteAsync(CancellationToken cancellationToken)
 20    {
 21        var clientId = Query<string>("clientId", true) ?? Query<string>("client_id", true) ?? string.Empty;
 22        try
 23        {
 24            var methods = await broker.DiscoverAsync(tenantAccessor.TenantId, clientId, cancellationToken);
 25            HttpContext.Response.Headers.CacheControl = "no-store";
 26            return new(methods, methods.SingleOrDefault(x => x.IsPreferred)?.Key);
 27        }
 28        catch (InvalidOperationException)
 29        {
 30            HttpContext.Response.StatusCode = 400;
 31            return new([], null);
 32        }
 33    }
 34}
 35
 36/// <summary>The preferred method is visual metadata only; clients must always render an explicit chooser.</summary>
 337internal sealed record DiscoverLoginMethodsResponse(IReadOnlyCollection<LoginMethod> Methods, string? PreferredMethodKey

Methods/Properties

get_Methods()