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