< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Broker.LogoutRequest
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Broker/Logout.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 61
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_ClientId()100%11100%
get_PostLogoutRedirectUri()100%11100%
get_Mode()100%11100%

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{
 240    public string? ClientId { get; set; }
 241    public string? PostLogoutRedirectUri { get; set; }
 242    public string? Mode { get; set; }
 43}
 44
 45internal sealed record LogoutResponse(bool Completed, string? NavigationUrl, string? RedirectUri);
 46
 47internal sealed class ContinueLogout(IExternalAuthenticationBroker broker) : ElsaEndpointWithoutRequest
 48{
 49    public override void Configure() => Get("/external-authentication/logout/continue/{handle}");
 50
 51    public override async Task HandleAsync(CancellationToken cancellationToken)
 52    {
 53        var result = await broker.ContinueLogoutAsync(Route<string>("handle")!, cancellationToken);
 54        if (result.Error is not null || result.NavigationUri is null)
 55        {
 56            HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
 57            return;
 58        }
 59        HttpContext.Response.Redirect(result.NavigationUri.ToString());
 60    }
 61}