Skip to content

Gitea, Forgejo and Codeberg

Forgejo speaks the Gitea API, and Codeberg runs Forgejo, so one provider covers all three. Use gitea(…) or its alias forgejo(…).

It works like the GitHub storage: one JSON file per page on an annotations branch, created from the default branch on the first save, and each note a commit by its author. Readers sign in with their account on your server, and only people with write access to the repository (or admins and the owner) may annotate.

  1. Open Settings → Applications on your server (https://codeberg.org/user/settings/applications on Codeberg). An organization can own the application instead, under its own settings.

  2. Under Manage OAuth2 applications, fill in:

    Field Value
    Application name Something readers recognize, e.g. Acme docs – annotations
    Redirect URIs https://docs.example.com/_annotations/callback (with your site base before /_annotations if you have one)
    Confidential client On
  3. Create it, and copy the Client ID and the Client secret (shown once).

In Settings → Applications → Generate new token, on an account with write access to the repository (a dedicated bot account works well):

  • Repository and Organization access: the repository, or all if your version cannot narrow it.
  • Permissions: repository: Read and write.
Terminal window
openssl rand -hex 32
import { createAnnotationsHandler, gitea } from 'starlight-annotations/server';
const handle = createAnnotationsHandler(
gitea({
host: 'https://codeberg.org', // or your Gitea / Forgejo
repo: 'owner/docs',
token: env.GITEA_TOKEN,
clientId: env.GITEA_CLIENT_ID,
clientSecret: env.GITEA_CLIENT_SECRET,
sessionSecret: env.ANNOTATIONS_SECRET,
}),
);

Mount it like the GitHub handler: see Cloudflare Workers or other hosts. branch, dir, writers and commitMessage work as for GitHub. Commits use the reader’s <login>@noreply.<host> address.

What you see What to do
“<login> may not annotate these docs” Give the person write access to the repository, or check that the server token can read it
The server rejects the redirect URI Make it exactly https://<site><base>/_annotations/callback
Saving fails with “The annotation service failed” The token expired or lacks repository: Read and write, or the annotations branch is protected