Single sign-on
How companion services (wiki, website) sign admins in via Clipr – protocol, checks, keys.
Companion services have no accounts of their own. Admins sign in via Clipr, which issues short-lived, signed one-time tickets for this. Code: app/clipr/sso.py, app/clipr/api/sso.py, in the wiki wiki/clipr_wiki/auth.py.
Flow
sequenceDiagram
participant B as Browser
participant D as Service (wiki)
participant C as Clipr
B->>D: /_auth/login
D->>B: state cookie, 302 → Clipr /sso/authorize?client=wiki&state=S
B->>C: /sso/authorize (Clipr session)
C->>C: admin? 2FA requirement? service registered?
C->>B: 303 → service /_auth/callback?ticket=T&state=S
B->>D: /_auth/callback
D->>D: check signature, iss, aud, time, jti, state
D->>B: own session (cookie, SameSite=Strict)
Note over D,C: on every writing action
D->>C: POST /sso/introspect {gid, aud}
C->>D: {active: true|false}
The ticket
Format v1.<payload>.<signature>, both Base64url. The signature covers clipr-sso-v1. + payload with Ed25519 – the prefix separates these signatures from every other purpose.
| Field | Meaning |
|---|---|
v |
Version (1) |
kid |
Key ID |
iss |
Issuer = CLIPR_PUBLIC_URL or https://CLIPR_DOMAIN |
aud |
Exactly one recipient origin, e.g. https://wiki.example.org |
sub |
Account ID on this instance – never the email address |
name |
Display name |
adm, mfa |
Admin role (always true), session with second factor |
iat, exp |
Issued, expires (60 seconds) |
jti |
One-time ID against reuse |
gid |
Secret grant ID (256 bit) for follow-up checks |
st |
SHA-256 of the state – binds the ticket to the browser |
Checks at the service
A ticket is only valid if everything matches: signature with a known key (fixed algorithm, nothing in the ticket can change it), issuer, audience, validity (at most 120 s span, 30 s clock skew), admin flag, state matching this browser's cookie, jti never seen before.
The service then creates its own session and asks back via /sso/introspect on every writing action (from the cache at most every 60 s). Clipr checks again: grant present and not expired (12 h), service still registered, originating Clipr session still valid, account active, admin role and 2FA requirement met. If Clipr cannot be reached, the service refuses.
Registering services
Redirects only go to fixed, configured origins – there is no free redirect parameter:
- Wiki: automatically when
CLIPR_WIKI_EDIT=1andCLIPR_WIKI_DOMAINare set. - Further services:
CLIPR_SSO_CLIENTS=name=https://host[:port],…
Keys
- Every instance creates its own Ed25519 key pair. A ticket from instance A is worthless to a service that trusts instance B.
- The private key is stored only encrypted in the system database: AES-256-GCM with
server:sso-signing, bound to the key ID. No endpoint, CLI command or log reveals it. GET /sso/keysreturns the public keys. The wiki fetches them internally; a service on another machine should pin them (for the wikiCLIPR_WIKI_SSO_KEYS).- Rotation:
python -m clipr.cli rotate-sso-key. The old key keeps verifying running tickets for one hour.
Security considerations and limits: Security.