< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.InitiateLocal
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/InitiateLocal.cs
Line coverage
76%
Covered lines: 13
Uncovered lines: 4
Coverable lines: 17
Total lines: 56
Line coverage: 76.4%
Branch coverage
50%
Covered branches: 9
Total branches: 18
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()50%301866.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/InitiateLocal.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
 712internal sealed class InitiateLocal(IExternalAuthenticationBroker broker, ITenantAccessor tenantAccessor) : ElsaEndpoint
 13{
 14    public override void Configure()
 15    {
 616        Post("/external-authentication/local/authorize");
 617        AllowAnonymous();
 1218        Options(x => x.RequireRateLimiting(ExternalAuthenticationRateLimitPolicyNames.LocalInitiation));
 619    }
 20
 21    public override async Task HandleAsync(InitiateLocalRequest request, CancellationToken cancellationToken)
 22    {
 123        if (!Uri.TryCreate(request.RedirectUri, UriKind.Absolute, out var redirectUri))
 24        {
 025            await BrokerEndpointSupport.SendErrorAsync(Send, BrokerErrorFactory.Create(BrokerErrorCategory.InvalidReques
 026            return;
 27        }
 28
 129        var result = await broker.InitiateLocalAsync(new LocalBrokerAuthorizationRequest(
 130            request.ClientId ?? string.Empty, redirectUri, request.ResponseType ?? string.Empty, request.CodeChallenge ?
 131            request.CodeChallengeMethod ?? string.Empty, request.ReturnPath ?? string.Empty, request.Username ?? string.
 132            request.Password ?? string.Empty, request.State), tenantAccessor.TenantId, cancellationToken);
 133        if (result.Error is { } error)
 34        {
 035            await BrokerEndpointSupport.SendErrorAsync(Send, error, cancellationToken);
 036            return;
 37        }
 38
 139        await Send.OkAsync(new InitiateLocalResponse(result.RedirectUri!.ToString()), cancellationToken);
 140    }
 41}
 42
 43internal sealed class InitiateLocalRequest
 44{
 45    public string? ClientId { get; set; }
 46    public string? RedirectUri { get; set; }
 47    public string? ResponseType { get; set; }
 48    public string? CodeChallenge { get; set; }
 49    public string? CodeChallengeMethod { get; set; }
 50    public string? ReturnPath { get; set; }
 51    public string? State { get; set; }
 52    public string? Username { get; set; }
 53    public string? Password { get; set; }
 54}
 55
 56internal sealed record InitiateLocalResponse(string RedirectUri);