Skip to content

Use a GitHub App

Store notes on GitHub uses an OAuth app for sign-in and a personal access token for the server. A GitHub App replaces both:

OAuth app + personal token GitHub App
Things to create Two (an OAuth app and a token) One
Belongs to A person: if they leave, the token stops working The app, not a person
In an organization The token waits for an owner to approve it, and expires An owner installs the app once; it does not expire
Access Whatever the token was given Contents and Metadata on the one repository it is installed on
Server credential The token itself, valid for months A key that mints tokens valid for one hour, limited to repo
Commits Committed by the token’s owner Committed by the app (your-app[bot]); the reader is still the author

Use it when the notes repository belongs to an organization, or when the setup should not depend on one person’s account.

You still need the session secret of the GitHub guide, and the choice of repository is the same.

Create it where the notes repository lives:

  • Organization repository: in the organization, at Settings → Developer settings → GitHub Apps → New GitHub App. This needs an owner or a GitHub App manager of the organization.
  • Personal repository: at github.com/settings/apps/new.
  1. GitHub App name: anything unique on GitHub, for example acme-docs-annotations. Readers see it on the sign-in page, and commits show it as acme-docs-annotations[bot].

  2. Homepage URL: your docs site.

  3. Callback URL: https://<your site><base>/_annotations/callback, for example https://docs.example.com/_annotations/callback. Use Add Callback URL for more, such as a preview domain, or http://localhost:8787/_annotations/callback to test with wrangler dev.

  4. Expire user authorization tokens: leave it as it is. The plugin uses the reader’s token once, at sign-in, and drops it.

  5. Request user authorization (OAuth) during installation: leave it unticked.

  6. Webhook: untick Active. The plugin needs no webhooks.

  7. Permissions → Repository permissions:

    • Contents: Read and write, to read and commit notes.
    • Metadata: Read-only, which GitHub selects by itself. It lets the server check who has write access.

    Leave everything else, including all Account permissions, at No access. (Only to email the author of a note: Account permissions → Email addresses: Read-only. Only to open issues from notes: Repository permissions → Issues: Read and write.)

  8. Where can this GitHub App be installed? Only on this account, if you created it in the account that owns the repository. If you created it in your personal account but the repository belongs to an organization, choose Any account, so the organization can install it.

  9. Press Create GitHub App.

On the app’s General page:

  1. Copy the App ID (a number) and the Client ID (it starts with Iv). Neither is secret.

  2. Under Client secrets, press Generate a new client secret and copy it now: GitHub shows it once.

  3. Under Private keys, press Generate a private key. GitHub downloads a .pem file. It is the server credential: keep it like a password, and delete the file once it is stored as a secret.

3. Install the app on the notes repository

Section titled “3. Install the app on the notes repository”
  1. On the app’s page, open Install App and press Install next to the account that owns the repository.

  2. Choose Only select repositories and pick the notes repository. Then Install.

Pass app instead of token, and the app’s client ID and secret for sign-in:

import { createAnnotationsHandler, github } from 'starlight-annotations/server';
const annotations = createAnnotationsHandler(
github({
repo: env.ANNOTATIONS_REPO,
app: {
appId: env.GITHUB_APP_ID,
privateKey: env.GITHUB_APP_PRIVATE_KEY,
},
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
sessionSecret: env.ANNOTATIONS_SECRET,
}),
);
Variable Kind Value
ANNOTATIONS_REPO plain owner/name of the notes repository
GITHUB_APP_ID plain The App ID
GITHUB_CLIENT_ID plain The app’s Client ID (Iv…)
GITHUB_CLIENT_SECRET secret The app’s client secret
GITHUB_APP_PRIVATE_KEY secret The whole .pem file, header lines included
ANNOTATIONS_SECRET secret The session secret

On Cloudflare, store the key straight from the file, so its line breaks survive:

Terminal window
npx wrangler secret put GITHUB_APP_PRIVATE_KEY < acme-docs-annotations.2026-11-13.private-key.pem

Where a variable cannot hold line breaks, write them as \n: the plugin accepts that too. Both key formats work: the BEGIN RSA PRIVATE KEY file GitHub downloads, and BEGIN PRIVATE KEY.

The server finds the installation by itself. To skip that lookup, pass installationId, the number at the end of the installation’s settings URL.

Sign in on the published site and save a note. Then, in the notes repository:

  • An annotations branch exists, with one file per annotated page.
  • The commit’s author is the reader, and the committer is your-app[bot]. GitHub marks it Verified.
What you see Why What to do
“The annotation service failed”, and the logs say the GitHub App … is not installed on owner/name The app is not installed on that repository, or the installation request is still waiting for an owner Install it (step 3), or ask an owner to approve the request
“The annotation service failed”, and the logs say GitHub App token 401 The App ID and the private key do not match, or the key was revoked Check GITHUB_APP_ID; generate a new key and store it again
“<login> may not annotate these docs” for someone with write access The installation does not include the notes repository In the installation settings, add the repository
A redirect_uri error on GitHub The callback URL is missing from the app Add https://<site><base>/_annotations/callback (step 1)
Logs mention must be a PEM The key secret is not the .pem file Store the whole file, -----BEGIN and -----END lines included

Create and install the app, set the new variables, and replace token with app. Readers sign in again once, because the client ID changed. Then revoke the old personal token and delete the old OAuth app. Notes, the branch and the file format do not change.