< Summary - Kestrun — Combined Coverage

Information
Class: Public.Cookies.Invoke-KrCookieSignOut
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Cookies/Invoke-KrCookieSignOut.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 65
Line coverage: 0%
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

Coverage history

Coverage history 0 25 50 75 100 09/12/2025 - 03:43:11 Line coverage: 0% (0/12) Total lines: 55 Tag: Kestrun/Kestrun@d160286e3020330b1eb862d66a37db2e26fc904209/16/2025 - 04:01:29 Line coverage: 0% (0/17) Total lines: 65 Tag: Kestrun/Kestrun@e5263347b0baba68d9fd62ffbf60a7dd87f994bb

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Cookies/Invoke-KrCookieSignOut.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Signs out the current user by removing their authentication cookie for the given scheme.
 4.DESCRIPTION
 5    Wraps SignOutAsync on the current HTTP context to remove a cookie-based session.
 6    Designed for use inside Kestrun route script blocks where $Context is available.
 7.PARAMETER Scheme
 8    Authentication scheme to use (default 'Cookies').
 9.PARAMETER Redirect
 10    If specified, redirects the user to the login path after signing out.
 11    If the login path is not configured, redirects to '/'.
 12.PARAMETER WhatIf
 13    Shows what would happen if the command runs. The command is not run.
 14.PARAMETER Confirm
 15    Prompts you for confirmation before running the command. The command is not run unless you respond
 16    affirmatively.
 17.EXAMPLE
 18    Invoke-KrCookieSignOut  # Signs out the current user from the default 'Cookies' scheme.
 19.EXAMPLE
 20    Invoke-KrCookieSignOut -Scheme 'MyCookieScheme'  # Signs out the current user from the specified scheme.
 21.OUTPUTS
 22    None
 23#>
 24function Invoke-KrCookieSignOut {
 25    [KestrunRuntimeApi('Route')]
 26    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', DefaultParameterSetName = 'SimpleIdentity')]
 27    [OutputType([System.Security.Claims.ClaimsPrincipal])]
 28    param(
 29        [Parameter()]
 30        [string]$Scheme = 'Cookies',
 31        [switch]$Redirect
 32    )
 33    # Only works inside a route script block where $Context is available
 034    if ($null -ne $Context -and $null -ne $KrServer) {
 035        if ($PSCmdlet.ShouldProcess($Scheme, 'SignOut')) {
 36            # Sign out the user
 037            if ($Context.User -and $Context.User.Identity.IsAuthenticated) {
 038                [Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions]::SignOutAsync($Context.HttpCon
 39            }
 40
 041            if ($Redirect) {
 042                $cookiesAuth = $null
 043                if ($KrServer.RegisteredAuthentications.Exists($Scheme, "Cookie")) {
 044                    $cookiesAuth = $KrServer.RegisteredAuthentications.Get($Scheme, "Cookie")
 45                } else {
 046                    Write-KrLog -Level Warning -Message 'Authentication scheme {scheme} not found in registered authenti
 047                    Write-KrErrorResponse -Message "Authentication scheme '$Scheme' not found." -StatusCode 400
 48                    return
 49                }
 050                Write-KrLog -Level Information -Message 'User {@user} signed out from {scheme} authentication.' -Values 
 51                # Redirect to login path or root
 52
 053                if ($null -ne $cookiesAuth -and $cookiesAuth.LoginPath -and $cookiesAuth.LoginPath.ToString().Trim()) {
 054                    $url = $cookiesAuth.LoginPath
 55                } else {
 056                    $url = '/'
 57                }
 058                Write-KrLog -Level Information -Message 'Redirecting {user} after logout to {path}' -Values $Context.Use
 059                Write-KrRedirectResponse -Url $url
 60            }
 61        }
 62    } else {
 063        Write-KrOutsideRouteWarning
 64    }
 65}

Methods/Properties

Invoke-KrCookieSignOut()