< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.InitiateExternalRequest
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/InitiateExternal.cs
Line coverage
25%
Covered lines: 2
Uncovered lines: 6
Coverable lines: 8
Total lines: 58
Line coverage: 25%
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_ConnectionKey()100%11100%
get_ClientId()100%210%
get_RedirectUri()100%210%
get_ResponseType()100%210%
get_CodeChallenge()100%210%
get_CodeChallengeMethod()100%210%
get_ReturnPath()100%210%
get_State()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/InitiateExternal.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 InitiateExternal(IExternalAuthenticationBroker broker, ITenantAccessor tenantAccessor) : ElsaEndpo
 13{
 14    public override void Configure()
 15    {
 16        Get("/external-authentication/authorize/{connectionKey}");
 17        AllowAnonymous();
 18        Options(x => x.RequireRateLimiting(ExternalAuthenticationRateLimitPolicyNames.ExternalInitiation));
 19    }
 20
 21    public override async Task HandleAsync(InitiateExternalRequest request, CancellationToken cancellationToken)
 22    {
 23        var clientId = Query<string>("client_id", false) ?? request.ClientId;
 24        var redirectUriValue = Query<string>("redirect_uri", false) ?? request.RedirectUri;
 25        var responseType = Query<string>("response_type", false) ?? request.ResponseType;
 26        var codeChallenge = Query<string>("code_challenge", false) ?? request.CodeChallenge;
 27        var codeChallengeMethod = Query<string>("code_challenge_method", false) ?? request.CodeChallengeMethod;
 28        var returnPath = Query<string>("return_path", false) ?? request.ReturnPath;
 29        if (!Uri.TryCreate(redirectUriValue, UriKind.Absolute, out var redirectUri))
 30        {
 31            await BrokerEndpointSupport.SendErrorAsync(Send, BrokerErrorFactory.Create(BrokerErrorCategory.InvalidReques
 32            return;
 33        }
 34
 35        var result = await broker.InitiateExternalAsync(new BrokerAuthorizationRequest(
 36            clientId ?? string.Empty, redirectUri, responseType ?? string.Empty, codeChallenge ?? string.Empty,
 37            codeChallengeMethod ?? string.Empty, returnPath ?? string.Empty, request.ConnectionKey ?? string.Empty, requ
 38        if (result.Error is { } error)
 39        {
 40            await BrokerEndpointSupport.SendErrorAsync(Send, error, cancellationToken);
 41            return;
 42        }
 43
 44        await Send.RedirectAsync(result.NavigationUri!.ToString(), false, true);
 45    }
 46}
 47
 48internal sealed class InitiateExternalRequest
 49{
 250    public string? ConnectionKey { get; set; }
 051    public string? ClientId { get; set; }
 052    public string? RedirectUri { get; set; }
 053    public string? ResponseType { get; set; }
 054    public string? CodeChallenge { get; set; }
 055    public string? CodeChallengeMethod { get; set; }
 056    public string? ReturnPath { get; set; }
 157    public string? State { get; set; }
 58}