< Summary - Kestrun — Combined Coverage

Information
Class: Public.Authentication.Add-KrOAuth2Authentication
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Authentication/Add-KrOAuth2Authentication.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 116
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/4) Total lines: 49 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 0% (0/16) Total lines: 116 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

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

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds OAuth 2.0 (Authorization Code) authentication to the Kestrun server.
 4.DESCRIPTION
 5    Configures the Kestrun server to use a generic OAuth 2.0 authorization-code flow.
 6    You can pass a prebuilt OAuthOptions object, or specify individual items (authority, paths, client, etc.).
 7.PARAMETER Server
 8    The Kestrun server instance to configure. If not specified, the current server instance is used.
 9.PARAMETER AuthenticationScheme
 10    The name of the OAuth authentication scheme (e.g., 'MyOAuth').
 11.PARAMETER DisplayName
 12    The display name for the authentication scheme (e.g., 'GitHub Login').
 13.PARAMETER Description
 14    A description of the OAuth authentication scheme.
 15.PARAMETER ClientId
 16    The OAuth client ID.
 17.PARAMETER ClientSecret
 18    The OAuth client secret.
 19.PARAMETER AuthorizationEndpoint
 20    The OAuth authorization endpoint URL.
 21.PARAMETER TokenEndpoint
 22    The OAuth token endpoint URL.
 23.PARAMETER CallbackPath
 24    The callback path for OAuth responses.
 25.PARAMETER SaveTokens
 26    If specified, saves the OAuth tokens in the authentication properties.
 27.PARAMETER UsePkce
 28    If specified, enables Proof Key for Code Exchange (PKCE) for enhanced security.
 29.PARAMETER ClaimPolicy
 30    An optional Kestrun.Claims.ClaimPolicyConfig to apply claim policies during authentication.
 31.PARAMETER Options
 32    An instance of Kestrun.Authentication.OAuth2Options containing the OAuth configuration.
 33.PARAMETER PassThru
 34    If specified, returns the modified Kestrun server object.
 35.EXAMPLE
 36    Add-KrOAuth2Authentication -AuthenticationScheme 'MyOAuth' -Options $oauthOptions
 37    Adds an OAuth2 authentication scheme named 'MyOAuth' using the provided options.
 38.NOTES
 39    This is a convenience wrapper around the C# extension AddOAuth2Authentication.
 40#>
 41function Add-KrOAuth2Authentication {
 42    [KestrunRuntimeApi('Definition')]
 43    [CmdletBinding()]
 44    [OutputType([Kestrun.Hosting.KestrunHost])]
 45    param(
 46        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 47        [Kestrun.Hosting.KestrunHost]$Server,
 48
 49        [Parameter(Mandatory = $false)]
 50        [string]$AuthenticationScheme = [Kestrun.Authentication.AuthenticationDefaults]::OAuth2SchemeName,
 51
 52        [Parameter(Mandatory = $false)]
 53        [string]$DisplayName = [Kestrun.Authentication.AuthenticationDefaults]::OAuth2DisplayName,
 54
 55        [Parameter(Mandatory = $false)]
 56        [string]$Description,
 57
 58        [Parameter(Mandatory = $false)]
 59        [string]$ClientId,
 60
 61        [Parameter(Mandatory = $false)]
 62        [string]$ClientSecret,
 63
 64        [Parameter(Mandatory = $false)]
 65        [string]$AuthorizationEndpoint,
 66
 67        [Parameter(Mandatory = $false)]
 68        [string]$TokenEndpoint,
 69
 70        [Parameter(Mandatory = $false)]
 71        [string]$CallbackPath,
 72
 73        [Parameter(Mandatory = $false)]
 74        [switch]$SaveTokens,
 75
 76        [Parameter(Mandatory = $false)]
 77        [switch]$UsePkce,
 78
 79        [Parameter(Mandatory = $false)]
 80        [Kestrun.Claims.ClaimPolicyConfig]$ClaimPolicy,
 81
 82        [Parameter(Mandatory = $false)]
 83        [Kestrun.Authentication.OAuth2Options]$Options,
 84
 85        [Parameter(Mandatory = $false)]
 86        [switch]$PassThru
 87    )
 88    begin {
 89        # Ensure the server instance is resolved
 090        $Server = Resolve-KestrunServer -Server $Server
 91    }
 92    process {
 093        if ($null -eq $Options) {
 94            # Build options from individual parameters if not provided
 095            $Options = [Kestrun.Authentication.OAuth2Options]::new()
 96        }
 97
 098        if ($ClientId) { $Options.ClientId = $ClientId }
 099        if ($ClientSecret) { $Options.ClientSecret = $ClientSecret }
 0100        if ($AuthorizationEndpoint) { $Options.AuthorizationEndpoint = $AuthorizationEndpoint }
 0101        if ($TokenEndpoint) { $Options.TokenEndpoint = $TokenEndpoint }
 0102        if ($CallbackPath) { $Options.CallbackPath = $CallbackPath }
 0103        if ($ClaimPolicy) { $Options.ClaimPolicy = $ClaimPolicy }
 0104        if ($Description) { $Options.Description = $Description }
 105
 0106        $Options.SaveTokens = $SaveTokens.IsPresent
 0107        $Options.UsePkce = $UsePkce.IsPresent
 108
 109        # Bridge to your C# extension (parallel to AddCookieAuthentication)
 0110        [Kestrun.Hosting.KestrunHostAuthnExtensions]::AddOAuth2Authentication(
 0111            $Server, $AuthenticationScheme, $DisplayName, $Options) | Out-Null
 0112        if ($PassThru.IsPresent) {
 0113            return $Server
 114        }
 115    }
 116}

Methods/Properties

Add-KrOAuth2Authentication()