< Summary - Kestrun — Combined Coverage

Information
Class: Public.Authentication.Add-KrOpenIdConnectAuthentication
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Authentication/Add-KrOpenIdConnectAuthentication.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 143
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 11/19/2025 - 02:25:56 Line coverage: 0% (0/5) Total lines: 52 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 0% (0/20) Total lines: 143 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

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

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds OpenID Connect (Authorization Code) authentication to the Kestrun server.
 4.DESCRIPTION
 5    Convenience wrapper around the C# extension AddOpenIdConnectAuthentication. Registers three schemes:
 6      <Name>, <Name>.Cookies, <Name>.Policy
 7    Enables PKCE and token persistence by default; supports custom scopes and callback path.
 8.PARAMETER Server
 9    The Kestrun server instance. If omitted, uses the current active server.
 10.PARAMETER AuthenticationScheme
 11    Base scheme name (default 'Oidc').
 12.PARAMETER DisplayName
 13    The display name for the authentication scheme (default is the OpenID Connect default display name).
 14.PARAMETER Description
 15    A description of the OpenID Connect authentication scheme.
 16.PARAMETER Authority
 17    The OpenID Connect authority URL.
 18.PARAMETER ClientId
 19    The OpenID Connect client ID.
 20.PARAMETER ClientSecret
 21    The OpenID Connect client secret.
 22.PARAMETER AuthorizationEndpoint
 23    The OpenID Connect authorization endpoint URL.
 24.PARAMETER TokenEndpoint
 25    The OpenID Connect token endpoint URL.
 26.PARAMETER ResponseType
 27    The OpenID Connect response type (default is 'Code').
 28.PARAMETER CallbackPath
 29    The callback path for OpenID Connect responses.
 30.PARAMETER SignedOutCallbackPath
 31    The callback path for sign-out responses.
 32.PARAMETER SaveTokens
 33    If specified, saves the OpenID Connect tokens in the authentication properties.
 34.PARAMETER UsePkce
 35    If specified, enables Proof Key for Code Exchange (PKCE) for enhanced security.
 36.PARAMETER GetClaimsFromUserInfoEndpoint
 37    If specified, retrieves additional claims from the UserInfo endpoint.
 38.PARAMETER ClaimPolicy
 39    An optional Kestrun.Claims.ClaimPolicyConfig to apply claim policies during authentication.
 40.PARAMETER Options
 41    An instance of Kestrun.Authentication.OidcOptions containing the OIDC configuration.
 42.PARAMETER PassThru
 43    Return the modified server object.
 44.EXAMPLE
 45    Add-KrOpenIdConnectAuthentication -Authority 'https://example.com' -ClientId $id -ClientSecret $secret
 46.EXAMPLE
 47    Add-KrOpenIdConnectAuthentication -AuthenticationScheme 'AzureAD' -Authority $authority -ClientId $id -ClientSecret 
 48#>
 49function Add-KrOpenIdConnectAuthentication {
 50    [KestrunRuntimeApi('Definition')]
 51    [CmdletBinding()]
 52    [OutputType([Kestrun.Hosting.KestrunHost])]
 53    param(
 54        [Parameter(ValueFromPipeline = $true)]
 55        [Kestrun.Hosting.KestrunHost]$Server,
 56
 57        [Parameter(Mandatory = $false)]
 58        [string]$AuthenticationScheme = [Kestrun.Authentication.AuthenticationDefaults]::OidcSchemeName,
 59
 60        [Parameter(Mandatory = $false)]
 61        [string]$DisplayName = [Kestrun.Authentication.AuthenticationDefaults]::OidcDisplayName,
 62
 63        [Parameter(Mandatory = $false)]
 64        [string]$Description,
 65
 66        [Parameter(Mandatory = $false)]
 67        [string]$Authority,
 68
 69        [Parameter(Mandatory = $false)]
 70        [string]$ClientId,
 71
 72        [Parameter(Mandatory = $false)]
 73        [string]$ClientSecret,
 74
 75        [Parameter(Mandatory = $false)]
 76        [string]$AuthorizationEndpoint,
 77
 78        [Parameter(Mandatory = $false)]
 79        [string]$TokenEndpoint,
 80
 81        [Parameter(Mandatory = $false)]
 82        [string]$CallbackPath,
 83
 84        [Parameter(Mandatory = $false)]
 85        [string]$SignedOutCallbackPath,
 86
 87        [Parameter(Mandatory = $false)]
 88        [Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectResponseType]$ResponseType,
 89
 90        [Parameter(Mandatory = $false)]
 91        [switch]$SaveTokens,
 92
 93        [Parameter(Mandatory = $false)]
 94        [switch]$UsePkce,
 95
 96        [Parameter(Mandatory = $false)]
 97        [switch]$GetClaimsFromUserInfoEndpoint,
 98
 99        [Parameter(Mandatory = $false)]
 100        [Kestrun.Claims.ClaimPolicyConfig]$ClaimPolicy,
 101
 102        [Parameter(Mandatory = $false)]
 103        [Kestrun.Authentication.OidcOptions]$Options,
 104
 105        [Parameter(Mandatory = $false)]
 106        [switch]$PassThru
 107    )
 108    begin {
 109        # Ensure the server instance is resolved
 0110        $Server = Resolve-KestrunServer -Server $Server
 111    }
 112    process {
 0113        if ( $null -eq $Options ) {
 114            # Build options from individual parameters if not provided
 0115            $Options = [Kestrun.Authentication.OidcOptions]::new()
 116        }
 0117        if ($Authority) { $Options.Authority = $Authority }
 0118        if ($ClientId) { $Options.ClientId = $ClientId }
 0119        if ($ClientSecret) { $Options.ClientSecret = $ClientSecret }
 0120        if ($AuthorizationEndpoint) { $Options.AuthorizationEndpoint = $AuthorizationEndpoint }
 0121        if ($TokenEndpoint) { $Options.TokenEndpoint = $TokenEndpoint }
 0122        if ($CallbackPath) { $Options.CallbackPath = $CallbackPath }
 0123        if ($SignedOutCallbackPath) { $Options.SignedOutCallbackPath = $SignedOutCallbackPath }
 0124        if ($ClaimPolicy) { $Options.ClaimPolicy = $ClaimPolicy }
 0125        if ($ResponseType) { $Options.ResponseType = $ResponseType }
 0126        if ($Description) { $Options.Description = $Description }
 0127        $Options.SaveTokens = $SaveTokens.IsPresent
 0128        $Options.UsePkce = $UsePkce.IsPresent
 0129        $Options.GetClaimsFromUserInfoEndpoint = $GetClaimsFromUserInfoEndpoint.IsPresent
 130        # Call C# extension with optional claim policy
 0131        [Kestrun.Hosting.KestrunHostAuthnExtensions]::AddOpenIdConnectAuthentication(
 132            $Server,
 133            $AuthenticationScheme,
 134            $DisplayName,
 135            $Options
 0136        ) | Out-Null
 137
 0138        if ($PassThru.IsPresent) {
 139            # if the PassThru switch is specified, return the modified server instance
 0140            return $Server
 141        }
 142    }
 143}