Skip to content

Fix AutoloadInstallations switch not triggering for GitHub App authentication #556

@MariusStorhaug

Description

Context

Connect-GitHubAccount (alias Connect-GitHub) provides an -AutoloadInstallations switch intended to automatically call Connect-GitHubApp after authenticating as a GitHub App. This is important for automation scenarios where GitHub App authentication should seamlessly produce Installation Access Token (IAT) contexts without requiring a separate manual step.

Request

When authenticating as a GitHub App via -ClientID + -PrivateKey (or -KeyVaultKeyReference) with the -AutoloadInstallations switch enabled, the switch has no effect. Connect-GitHubApp is never called, and only the APP context is created — no IAT contexts are produced.

What happens

Connect-GitHub -ClientID $clientId -PrivateKey $privateKey -AutoloadInstallations -Verbose
# Expected: Verbose output "Loading GitHub App Installation contexts..." followed by Connect-GitHubApp
# Actual: No verbose message, no IAT contexts created. Only the APP context exists.
Get-GitHubContext -ListAvailable
# Shows only the APP context, no IAT contexts

The user must explicitly call Connect-GitHubApp after Connect-GitHub to get IAT contexts, making the -AutoloadInstallations switch dead code.

What is expected

When -AutoloadInstallations is specified during GitHub App authentication, Connect-GitHubApp should be called automatically after the APP context is created. The user should see IAT contexts for all installations without needing a second command.

Acceptance criteria

  • -AutoloadInstallations triggers Connect-GitHubApp when authenticating as a GitHub App
  • IAT contexts are created automatically for all app installations
  • Verbose output confirms the autoload behavior
  • Existing behavior for non-App authentication is unchanged

Technical decisions

Root cause: In Connect-GitHubAccount.ps1 line 338, the autoload check references a local variable $authType:

if ($authType -eq 'App' -and $AutoloadInstallations) {
    Write-Verbose 'Loading GitHub App Installation contexts...'
    Connect-GitHubApp -Silent:$Silent
}

The variable $authType is only assigned inside the GitHub Actions token-detection block (line ~187), which is explicitly skipped for the 'GitHub App using a PrivateKey' and 'GitHub App using a KeyVault Key Reference' parameter sets. Therefore $authType is always $null for App authentication.

Fix approach: Replace $authType with $context['AuthType'], which is correctly set to 'APP' for GitHub App parameter sets. The comparison must also use 'APP' (uppercase) to match the stored value:

if ($context['AuthType'] -eq 'APP' -and $AutoloadInstallations) {

Case sensitivity: PowerShell's -eq operator is case-insensitive by default, so 'APP' -eq 'App' evaluates to $true. However, for clarity and consistency with the stored value, use 'APP'.

Test approach: Integration test that authenticates as a GitHub App with -AutoloadInstallations and verifies that Get-GitHubContext -ListAvailable returns IAT contexts in addition to the APP context.


Implementation plan

Core fix

  • Update the autoload condition in Connect-GitHubAccount.ps1 to use $context['AuthType'] instead of $authType
  • Verify the comparison value matches 'APP' (the stored AuthType for GitHub App contexts)

Tests

  • Add test verifying -AutoloadInstallations produces IAT contexts when authenticating as a GitHub App
  • Add test verifying -AutoloadInstallations has no effect for non-App authentication (regression guard)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpatch

    Type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions