Store notes on GitLab
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 GitLab, and only project members with the Developer role or higher may annotate.
The setup has the same three pieces: an OAuth application, a server token and a session secret. Read Before you start: which repository? on the GitHub page first: the same advice applies.
1. Create the OAuth application
Section titled “1. Create the OAuth application”-
Open User settings → Applications (
https://gitlab.com/-/user_settings/applicationson gitlab.com). A group owner can create it under the group’s Settings → Applications instead, so it does not depend on one person. -
Fill in the form:
Field Value Name Something readers recognize, e.g. Acme docs – annotationsRedirect URI https://docs.example.com/_annotations/callback(with your sitebasebefore/_annotationsif you have one)Confidential On Scopes read_useronly -
Save. Copy the Application ID (your
clientId) and the Secret (yourclientSecret; it is shown once).
2. Create the server token
Section titled “2. Create the server token”The server reads and commits notes with this token and checks who is a member.
- Project access token (Project → Settings → Access tokens), where your GitLab plan offers it: role Developer, scope
api. It belongs to the project, not to a person. - Otherwise a personal access token of a member with the Developer role or higher: scope
api.
Set an expiry date and a reminder: when the token expires, saving notes stops until you replace it.
3. Create the session secret
Section titled “3. Create the session secret”openssl rand -hex 324. Configure your server
Section titled “4. Configure your server”import { createAnnotationsHandler, gitlab } from 'starlight-annotations/server';
const handle = createAnnotationsHandler( gitlab({ host: 'https://gitlab.example.com', // leave out for gitlab.com project: 'group/docs', // path or numeric id token: env.GITLAB_TOKEN, clientId: env.GITLAB_CLIENT_ID, clientSecret: env.GITLAB_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.
Troubleshooting
Section titled “Troubleshooting”| What you see | What to do |
|---|---|
| “<login> may not annotate these docs: a Developer role or higher on the project is needed” | Give the person the Developer role, or check that the server token can read the project members (scope api) |
| GitLab says the redirect URI is invalid | Make the application’s Redirect URI exactly https://<site><base>/_annotations/callback |
| Saving fails with “The annotation service failed” | The token expired, lacks api, or its role cannot push to the annotations branch (check Protected branches) |