< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.ContinueLogout
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/Logout.cs
Line coverage
25%
Covered lines: 2
Uncovered lines: 6
Coverable lines: 8
Total lines: 61
Line coverage: 25%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
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()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/Logout.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.ExternalAuthentication.Constants;
 3using Elsa.ExternalAuthentication.Models;
 4using Elsa.ExternalAuthentication.Services;
 5using Elsa.Identity.Constants;
 6using FastEndpoints;
 7using Microsoft.AspNetCore.Http;
 8
 9namespace Elsa.ExternalAuthentication.Endpoints.Broker;
 10
 11internal sealed class Logout(IExternalAuthenticationBroker broker) : ElsaEndpoint<LogoutRequest>
 12{
 13    public override void Configure()
 14    {
 15        Post("/external-authentication/logout");
 16    }
 17
 18    public override async Task HandleAsync(LogoutRequest request, CancellationToken cancellationToken)
 19    {
 20        var sessionId = HttpContext.User.FindFirst(CustomClaimTypes.ExternalAuthenticationSessionId)?.Value;
 21        if (string.IsNullOrWhiteSpace(sessionId) || !Uri.TryCreate(request.PostLogoutRedirectUri, UriKind.Absolute, out 
 22        {
 23            await BrokerEndpointSupport.SendErrorAsync(Send, BrokerErrorFactory.Create(BrokerErrorCategory.InvalidReques
 24            return;
 25        }
 26
 27        var result = await broker.LogoutAsync(new BrokerLogoutRequest(request.ClientId ?? string.Empty, redirectUri, req
 28        if (result.Error is { } error)
 29        {
 30            await BrokerEndpointSupport.SendErrorAsync(Send, error, cancellationToken);
 31            return;
 32        }
 33
 34        await Send.OkAsync(new LogoutResponse(result.Completed, result.NavigationUri?.ToString(), result.RedirectUri?.To
 35    }
 36}
 37
 38internal sealed class LogoutRequest
 39{
 40    public string? ClientId { get; set; }
 41    public string? PostLogoutRedirectUri { get; set; }
 42    public string? Mode { get; set; }
 43}
 44
 45internal sealed record LogoutResponse(bool Completed, string? NavigationUrl, string? RedirectUri);
 46
 647internal sealed class ContinueLogout(IExternalAuthenticationBroker broker) : ElsaEndpointWithoutRequest
 48{
 649    public override void Configure() => Get("/external-authentication/logout/continue/{handle}");
 50
 51    public override async Task HandleAsync(CancellationToken cancellationToken)
 52    {
 053        var result = await broker.ContinueLogoutAsync(Route<string>("handle")!, cancellationToken);
 054        if (result.Error is not null || result.NavigationUri is null)
 55        {
 056            HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
 057            return;
 58        }
 059        HttpContext.Response.Redirect(result.NavigationUri.ToString());
 060    }
 61}