Store notes on GitHub
With the GitHub storage, every note is a commit. Notes are JSON files on a branch of their own (default annotations), so they never touch your default branch and never trigger a deploy. Readers sign in with GitHub, and only people with write access to the repository may annotate.
You need three things. This page walks through each one.
| What | Who uses it | Secret? |
|---|---|---|
| OAuth app (client ID + client secret) | The reader’s browser, to sign in with GitHub | The client secret is |
| Server token | Your server, to read and commit notes and to check who has write access | Yes |
| Session secret | Your server, to sign the session cookie | Yes |
Before you start: which repository?
Section titled “Before you start: which repository?”Notes go to one repository, set with the repo option. Choose the one where the people who will annotate have write access:
- Your team reviews its own docs: the docs repository itself.
- A client or another team reviews: their repository, so the feedback stays with them and they need no access to yours.
1. Create the OAuth app
Section titled “1. Create the OAuth app”The OAuth app is how readers sign in. It asks for no permission: the plugin only reads who signed in.
-
Open the form for a new OAuth app:
- for your account: github.com/settings/applications/new
- for an organization: Organization settings → Developer settings → OAuth Apps → New OAuth App
Either works. An app owned by the organization does not depend on one person’s account.
-
Fill in the form:
Field Value Application name Something readers recognize, e.g. Acme docs – annotationsHomepage URL Your docs site, e.g. https://docs.example.comAuthorization callback URL https://docs.example.com/_annotations/callbackAllow wildcard matching Off Enable Device Flow Off Expire user access tokens Either; the plugin uses the reader’s token once, at sign-in If your site has a
base, put it before/_annotations:https://example.com/docs/_annotations/callback. The URL must match character for character. -
Press Register application. Copy the Client ID: it is not secret and goes in your configuration.
-
Press Generate a new client secret and copy it right away: GitHub shows it only once. Store it as a secret of your host (see step 4), never in the repository or in chat.
2. Create the server token
Section titled “2. Create the server token”The server reads and commits notes with this token, and asks GitHub whether the person signing in has write access. Use a fine-grained personal access token limited to one repository.
-
Fill in the form:
Field Value Token name e.g. docs-annotationsDescription e.g. Commits reader notes to the annotations branch Resource owner The owner of the notes repository: your account, or the organization Expiration Up to a year. Set a reminder: when it expires, saving notes stops until you replace it Repository access Only select repositories → the notes repository Repository permissions Contents: Read and write. Metadata: Read-only is added for you -
Press Generate token and copy it. Like the client secret, it goes into your host’s secrets.
-
If the resource owner is an organization, check the token in your token list. If it shows Pending, the organization requires an owner to approve it, and the token cannot reach the repository until then. Ask an owner to approve it at:
https://github.com/organizations/<org>/settings/personal-access-token-requestsApproval takes effect at once; you do not need a new token or a new deploy.
3. Create the session secret
Section titled “3. Create the session secret”Any long random string. It signs the session cookie, so a reader stays signed in for 30 days without the server keeping any state. Their write access is still checked again every minute or so, so removing someone from the repository signs them out.
openssl rand -hex 32Changing it later signs everybody out.
4. Configure your server
Section titled “4. Configure your server”Pass everything to the handler. With environment variables:
import { createAnnotationsHandler, github } from 'starlight-annotations/server';
const handle = createAnnotationsHandler( github({ repo: env.ANNOTATIONS_REPO, // 'owner/name' token: env.GITHUB_TOKEN, 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_CLIENT_ID |
plain | From step 1 |
GITHUB_CLIENT_SECRET |
secret | From step 1 |
GITHUB_TOKEN |
secret | From step 2 |
ANNOTATIONS_SECRET |
secret | From step 3 |
Where the handler goes depends on your host: see Cloudflare Workers or other hosts. Options such as branch, writers and commitMessage are in the server reference.
Until every value is set, keep the handler from answering (or answer 503): the pages then show no annotation UI, so you can deploy the plugin before the server is ready.
5. Check it works
Section titled “5. Check it works”- Open your published docs, select some text and press Annotate.
- Press Sign in with GitHub and authorize the app. You come back to the same page, signed in.
- Write a note and save it.
- On GitHub, the repository now has an
annotationsbranch, created from the default branch, with a commit by you that addsannotations/<page>.json.
From then on, every note, reply, resolve and delete is a commit on that branch. Review them like any other history: git log annotations, or the branch on GitHub.
Open an issue from a note
Section titled “Open an issue from a note”When a note turns into work, turn it into a GitHub issue. Add issues to the options:
github({ ...options, issues: true }); // or { repo: 'owner/tracker' } for another repositoryEvery open thread then has Open issue. Anyone who can write notes can press it. The server opens the issue with its own credential and the note is resolved, with a link to the issue in the panel and on the overview page. The issue has:
- Title: the first line of the note.
- Body:
- the quoted passage, or “Whole page”;
- for a suggested edit, a
diffblock with the old and the new text; - a link back to the note;
- the whole conversation, people shown as links to their profile, so opening the issue notifies nobody by itself;
- who opened it.
- Label: the note’s kind, if it has one:
question,problem,proposalordecision. GitHub creates the label if it is missing; if it refuses, the issue is opened without it.
The server credential needs to write issues: a fine-grained token with Issues: Read and write, or a GitHub App with that repository permission (accept the new permission on the installation). Closing or reopening the issue does not change the note.
Troubleshooting
Section titled “Troubleshooting”| What you see | Why | What to do |
|---|---|---|
| “<login> may not annotate these docs” after signing in | Either the person has no write access to the repository, or the server token cannot see the repository: it is still Pending approval, its resource owner is wrong, or the repository is not selected | Check the person’s role on the repository. Then check the token in your token list: owner, selected repository, Pending badge |
| A redirect_uri error on GitHub instead of the authorize page | The callback URL in the OAuth app does not match the site | Make it exactly https://<site><base>/_annotations/callback |
| “The sign-in link expired. Try again.” | The sign-in took more than 10 minutes, or cookies are blocked | Sign in again; allow cookies for the site |
| No Annotate button on the published site | The API answers an error or nothing, so the UI stays hidden | Open /_annotations/api?page=index: 503 means a setting is missing, 404 means the handler is not mounted at that path |
| “Could not open an issue on …” | Issues are turned off on that repository, or the credential lacks Issues: Read and write | Turn issues on in the repository settings, or add the permission to the token or the app |
| “The annotation service failed” when saving | GitHub refused the write: the token expired, or lost Contents: Read and write | Check the server logs for the GitHub status, renew the token and update the secret |
Rotating and revoking
Section titled “Rotating and revoking”- Token expired or leaked: create a new one (step 2), replace the
GITHUB_TOKENsecret, delete the old one. Readers stay signed in. - Client secret leaked: generate a new one in the OAuth app, replace
GITHUB_CLIENT_SECRET, delete the old one. - Sign everybody out: replace
ANNOTATIONS_SECRET. - Turn notes off: remove the token or revoke it. The rest of the site keeps working; the annotation UI disappears.