@novren/id-verifier
For your server (Node 18+ or any runtime with fetch): verifies access tokens, follows revocations, reports deleted accounts.
import { createTokenVerifier, watchAccountEvents, TokenRejected } from '@novren/id-verifier'Tokens
createTokenVerifier(options)
| Option | Type | Default | Meaning |
|---|---|---|---|
idServerUrl | string | https://id.novren.net | |
product | string | your app id: the only accepted aud | |
serviceToken | string | your service token (reads the revocation feed) | |
pollMs | number? | 5000 | how often the revocation feed is read |
maxStalenessMs | number? | 60000 | how long without a read before refusing everything |
keys | JWTVerifyGetKey? | remote JWKS | for tests: a key set instead of /.well-known/jwks.json |
Returns a TokenVerifier:
start(): Promise<void>
Reads the revocation feed once, then every pollMs. Doesn't throw if the first read fails (the next verify calls answer unavailable until a read succeeds). The timer doesn't keep the process alive.
stop(): void
Stops reading.
sync(): Promise<void>
Reads the feed now. Throws if the read fails. Useful right before a sensitive action, and in tests.
verify(token): Promise<AccessTokenClaims>
Checks, in this order:
- that there is a token and the feed was read in the last
maxStalenessMs; - EdDSA signature with Novren ID's public keys (cached),
iss = https://id.novren.net,aud = product,typ = at+jwt, not expired, claimssub,sid,exp,iat,jtipresent; - the chain (
sid) is not closed, and the account didn't revoke everything afteriat.
Returns the claims: iss, sub, aud, iat, exp, jti, sid, plan. See Tokens.
Throws TokenRejected.
TokenRejected
Error with a reason:
reason | Cause | Suggested status |
|---|---|---|
invalid | missing, malformed, wrong signature, wrong app, expired | 401 |
revoked | chain closed or account revoked everything | 401 |
unavailable | feed not read for maxStalenessMs | 503 |
Account events
watchAccountEvents(options)
| Option | Type | Default | Meaning |
|---|---|---|---|
idServerUrl | string | https://id.novren.net | |
serviceToken | string | your service token | |
onAccountDeleted | (accountId) => Promise<void> | delete everything of the account. Idempotent | |
onServiceLeft | (accountId, before: Date) => Promise<void> | skipped | the user removed only your app: delete what was created before before |
pollMs | number? | 60000 | how often new events are read |
fullResyncMs | number? | 6 hours | how often the whole 90-day window is re-read |
onError | (error) => void | console.error | failed read or handler |
Returns an AccountEventsWatcher:
start(): void
First read at once, then every pollMs. Errors go to onError.
stop(): void
Stops reading.
sync(): Promise<number>
A read now; resolves to the number of events handled. Two concurrent calls share one read.
Behaviour: the position is kept in memory and starts from 0 at every start and every fullResyncMs, so events are delivered more than once and none is lost. If a handler throws, the watcher stops at that event and retries it at the next read. Without onServiceLeft, service-left events are skipped and your app keeps the data. See Deleted accounts.