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

Methods/Properties

get_Methods()