github-app-tokens
Use when a GitHub credential needs to come into existence, live somewhere, and die — constructing a client from a plain token or a GitHub App, or wiring GitHubToken's provision/read/clientLayer/dispose lifecycle across an Action's pre/main/post phases.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 8
- Forks
- 2
01 前言 Front Matter
- name
- github-app-tokens
- description
- Use when a GitHub credential needs to come into existence, live somewhere, and die — constructing a client from a plain token or a GitHub App, or wiring GitHubToken's provision/read/clientLayer/dispose lifecycle across an Action's pre/main/post phases.
- when_to_use
- GitHubApp, installation token, App JWT, appClientLayer, cachedToken, cachedClientLayer, InstallationTokenStore, PKCS#1 private key, token bridge, GitHubTokenError, botIdentity, TokenPermissionError, revoke on release, acquireUseRelease token, GITHUB_STATE persisted token, plain GITHUB_TOKEN input
02 资源文件 2
- 参考文档references/client-construction.md8.2 KB
- 参考文档references/token-lifecycle.md11.7 KB
03 SKILL.md 正文
GitHub App tokens: the credential lifecycle
Two packages, one lifecycle: how a GitHub credential comes into existence,
where it lives, and when it dies. @effected/github mints and revokes;
@effected/github-actions persists a mint across a process boundary and
guarantees it dies exactly once. For the request surface itself
(client.request, GitHubError, pagination) see github-api. For wiring
Action.run and ActionRunOptions.layer, see actions-runtime. For the
Secret seam and ActionState, see actions-state-and-secrets.
What you have
| Construct | Import | Reach for it when |
|---|---|---|
GitHubClient.layerFromToken |
import { GitHubClient } from "@effected/github" |
You already hold a Redacted<string> token |
GitHubClient.layerFromConfig |
@effected/github |
The workflow's own runner-issued token is enough |
GitHubApp (.token, .scopedToken, .revoke, .identity, .botUser, .installations, .clientLayer, .appClientLayer, .cachedToken, .cachedClientLayer) |
@effected/github |
Minting/revoking an installation token directly, outside an Action's process boundary; speaking as the app itself; reusing a token across request scopes through an InstallationTokenStore |
TokenPermissions |
@effected/github |
Comparing a token's granted scopes against what a program requires |
BotIdentity |
@effected/github |
Rendering a DCO trailer, or naming the bot identity behind a token |
GitHubToken (.provision, .read, .botIdentity, .clientLayer, .dispose) |
import { GitHubToken } from "@effected/github-actions" |
Bridging an App-minted token across an Action's pre/main/post process boundary |
Standards
- Pick the plain-token path first.
GitHubClient.layerFromConfig()needs noActionState, noGitHubApp, no revoke lifecycle — reach for App auth only when the runner's own token can't provide a permission or a distinct bot identity your program needs. GitHubApp.clientLayerlives onGitHubApp, notGitHubClient. A layer-family static belongs to the module that owns the dependency it needs; putting it onGitHubClientwould drag the JWT signer into every token-only consumer's bundle. Seereferences/client-construction.md.- Use
GitHubToken, neverGitHubApp.scopedToken/.clientLayer, inside an Action. Both revoke on theirScope's close, and in an Action the scope closes at the end ofpre— beforemainruns a single request.GitHubTokenpersists the mint throughGITHUB_STATEinstead. - Build a
layerTestfrom the member-usage table, not from a stack trace. EachGitHubTokenmember touches an exact, documented set ofActionState/ActionOutputs/GitHubAppmembers — stub exactly those. Seereferences/token-lifecycle.md. - Verify required scope at
pre, not by waiting for a 403 inmain. SetGitHubToken.provision'srequiredoption every time — leaving it unset skips verification silently. - Revoke the mint on any provisioning failure.
provisionis an acquire-use-release: a scope-verification or persistence failure revokes the just-minted token rather than leaving an hour of unreferenced access live for a retriedpre. postdisposes unconditionally, wrapped double-netted.dispose()is already a no-op with nothing to revoke, but still wrap the call incatch+catchDefect— apostphase must never turn a green run red over a token it was only trying to clean up.- Never reintroduce
@octokit/restor@octokit/auth-app. A small, zero-dependency JWT signer plus one typed route call covers what minting an installation token actually needs; both larger dependencies were deliberately dropped.
Footguns
- An installation token lives about an hour and nothing can re-mint one
after
pre— the only credential that could is the App's private key, and persisting that throughGITHUB_STATE(plaintext by GitHub's own protocol) would trade an hour-long token for a permanent one. A phase expecting to outlive the hour callsprovisionitself. - The scope-verification field is named
required, notpermissions—permissionsis the field on the minted token. A double or migration script that writespermissionsonProvisionOptionscompiles clean and silently skips verification. Seereferences/token-lifecycle.md. - Masking must happen before persistence — the ordering is structural in
provision, not a convention a caller has to remember; get it backwards in a hand-rolled variant and a plaintext token reachesGITHUB_STATEunmasked. disposereads withgetOptional, neverget— apostphase after aprethat failed before minting anything must be a no-op, not a typed failure.
Additional resources
- references/token-lifecycle.md — the
GitHubTokenbridge in full: the member-usage table, the one-hour contract,provision/clientLayer/disposemechanics, and the complete five-element App-auth recipe including how to add or remove it from an action. Load when: wiring App auth into an action'spre/main/postphases. - references/client-construction.md —
the five
GitHubClientconstructors (token, config, installation, app JWT, cached token) in detail, why the package skips@octokit/rest/@octokit/auth-app, theGitHubAppservice shape and its rotation/revocation mechanics, and the pureTokenPermissions/BotIdentityclasses. Load when: constructing a client directly, or working withGitHubAppoutside theGitHubTokenbridge.
Pointers
- The request surface (
client.request,GitHubError'skindtaxonomy, pagination, GraphQL) —github-api. - Wiring
Action.run,ActionRuntime.layer, and theActionRunOptions.layertype-level constraintclientLayer()'s fallible construction runs into —actions-runtime. - The
Secretdeclassification seam andActionStatepersistence —actions-state-and-secrets. - Testing doubles for any of the above (
layerTest, the member-usage-table pattern,TestClockfor expiry) —testing-actions.
04 同仓库更多 Skills
testing-actions
Use when writing or reviewing tests for @effected/github-actions, @effected/github, @effected/sbom or @effected/commands — stubbing the GitHub API, writing a service's layerTest or makeTest double, testing the pre/main/post lifecycle through Action.run, or debugging why a test hits the real network or hangs.
supply-chain-attestation
Use when generating a CycloneDX SBOM, checking NTIA minimum elements, building an in-toto statement or a SLSA provenance predicate, signing into a Sigstore DSSE bundle, or uploading an attestation to GitHub.
structuring-an-action
Use when laying out a new GitHub Action repository on the @effected suite, deciding where a piece of code belongs (an entry point, a step, a shared service, a shim), or reviewing an existing action's file structure against the canonical shape.
running-commands-and-tools
Use when running a subprocess in Effect v4, spawning a command, capturing stdout/stderr/exit code, checking whether a CLI tool is installed or which copy to run, running a package-manager script through the project's launcher, detaching a background process, or redacting a secret from argv or captured output.
release-and-publish
Use when publishing a package to npm, reading the npm registry from Effect v4, checking whether a version is already published, cutting a release tag or GitHub release from an action, applying a release-age gate, or deriving tracking tags for GitHub Actions distribution.
hardening-a-parser-port
Use when porting or writing a recursive-descent parser, lexer, or tree-walker over untrusted text in the @effected monorepo — the class of hardening the cloud reviewer scans for on every migration. Covers stack-overflow depth guards (on EVERY recursion surface, which a facade has N of — not two), numeric bound guards that must reject NaN and non-integers, code-point range checks scoped to formats with wide escapes, prototype-pollution, control-character rejection, and the invariant that malformed input must fail through the typed error channel, never as an unhandled defect.