< Summary - Kestrun — Combined Coverage

Information
Class: Public.Authentication.Add-KrWindowsAuthentication
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Authentication/Add-KrWindowsAuthentication.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
66%
Covered lines: 4
Uncovered lines: 2
Coverable lines: 6
Total lines: 48
Line coverage: 66.6%
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

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Authentication/Add-KrWindowsAuthentication.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds Windows authentication to the Kestrun server.
 4    .DESCRIPTION
 5        Configures the Kestrun server to use Windows authentication for incoming requests.
 6        This allows the server to authenticate users based on their Windows credentials.
 7        This enables the server to use Kerberos or NTLM for authentication.
 8    .PARAMETER Server
 9        The Kestrun server instance to configure.
 10    .PARAMETER PassThru
 11        If specified, returns the modified server instance after adding the authentication.
 12    .EXAMPLE
 13        Add-KrWindowsAuthentication -Server $myServer -PassThru
 14        This example adds Windows authentication to the specified Kestrun server instance and returns the modified insta
 15    .LINK
 16        https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.windowsauthentication?view=aspn
 17    .NOTES
 18        This cmdlet is used to configure Windows authentication for the Kestrun server, allowing you to secure your APIs
 19#>
 20function Add-KrWindowsAuthentication {
 21    [KestrunRuntimeApi('Definition')]
 22    [CmdletBinding(defaultParameterSetName = 'ItemsScriptBlock')]
 23    [OutputType([Kestrun.Hosting.KestrunHost])]
 24    param(
 25        [Parameter(Mandatory = $false, ValueFromPipeline)]
 26        [Kestrun.Hosting.KestrunHost]$Server,
 27
 28        [Parameter()]
 29        [switch]$PassThru
 30    )
 31    begin {
 32        # Ensure the server instance is resolved
 133        $Server = Resolve-KestrunServer -Server $Server
 134        if ($null -eq $Server) {
 035            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 36        }
 37    }
 38    process {
 39        # Add Windows authentication to the server instance ---
 240        [Kestrun.Hosting.KestrunHostAuthExtensions]::AddWindowsAuthentication($Server) | Out-Null
 141        if ($PassThru.IsPresent) {
 42            # if the PassThru switch is specified, return the server instance
 43            # Return the modified server instance
 044            return $Server
 45        }
 46    }
 47}
 48

Methods/Properties

Add-KrWindowsAuthentication()