< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.InitiateLocalResponse
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/InitiateLocal.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 56
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_RedirectUri()100%11100%

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
 12internal sealed class InitiateLocal(IExternalAuthenticationBroker broker, ITenantAccessor tenantAccessor) : ElsaEndpoint
 13{
 14    public override void Configure()
 15    {
 16        Post("/external-authentication/local/authorize");
 17        AllowAnonymous();
 18        Options(x => x.RequireRateLimiting(ExternalAuthenticationRateLimitPolicyNames.LocalInitiation));
 19    }
 20
 21    public override async Task HandleAsync(InitiateLocalRequest request, CancellationToken cancellationToken)
 22    {
 23        if (!Uri.TryCreate(request.RedirectUri, UriKind.Absolute, out var redirectUri))
 24        {
 25            await BrokerEndpointSupport.SendErrorAsync(Send, BrokerErrorFactory.Create(BrokerErrorCategory.InvalidReques
 26            return;
 27        }
 28
 29        var result = await broker.InitiateLocalAsync(new LocalBrokerAuthorizationRequest(
 30            request.ClientId ?? string.Empty, redirectUri, request.ResponseType ?? string.Empty, request.CodeChallenge ?
 31            request.CodeChallengeMethod ?? string.Empty, request.ReturnPath ?? string.Empty, request.Username ?? string.
 32            request.Password ?? string.Empty, request.State), tenantAccessor.TenantId, cancellationToken);
 33        if (result.Error is { } error)
 34        {
 35            await BrokerEndpointSupport.SendErrorAsync(Send, error, cancellationToken);
 36            return;
 37        }
 38
 39        await Send.OkAsync(new InitiateLocalResponse(result.RedirectUri!.ToString()), cancellationToken);
 40    }
 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
 256internal sealed record InitiateLocalResponse(string RedirectUri);

Methods/Properties

get_RedirectUri()