Skip to main content

Module token

Module token 

Source
Expand description

Centralized GitHub token resolution — supports env vars, GitHub App JWT, and gh CLI fallback.

This module provides a TokenResolver that caches token resolution and supports multiple modes:

  • env (default): Read from GH_TOKEN or GITHUB_TOKEN env vars, then gh.auth.token config, then gh auth token CLI (controlled by allow_gh_fallback, which defaults to true)
  • github_app: Generate JWT from app_id + private_key (for GitHub App authentication)

§Default behavior

Out of the box, TokenResolver::default() works with just gh auth login — no extra config needed. Resolution order:

  1. GH_TOKEN environment variable
  2. GITHUB_TOKEN environment variable
  3. gh.auth.token config value
  4. gh auth token CLI (via allow_gh_fallback = true)

Structs§

TokenResolver
Centralized token resolver for GitHub authentication.

Enums§

TokenMode
Token source mode for GitHub authentication.

Functions§

create_token_resolver
Create a global token resolver from configuration.
shared
Get the process-wide shared token resolver.