Setup
Generate a signing key
Create the module
lib/kavach.ts
GetUserClaimsFn callback. KavachOS calls it to build ID tokens and userinfo responses. You control what data is returned per scope.Register a client
clientSecret is only returned on registration. It is stored hashed. If you lose it, delete and re-register the client.Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
issuer | string | required | Issuer URL, e.g. https://auth.example.com |
signingKey | CryptoKey | JWK | required | RSA or EC private key for signing tokens |
signingAlgorithm | string | RS256 | JWT algorithm (RS256, ES256, etc.) |
accessTokenTtl | number | 3600 | Access token lifetime in seconds |
refreshTokenTtl | number | 2592000 | Refresh token lifetime in seconds (30 days) |
authCodeTtl | number | 600 | Authorization code lifetime in seconds |
idTokenTtl | number | 3600 | ID token lifetime in seconds |
supportedScopes | string[] | ['openid', 'profile', 'email'] | Scopes this provider accepts |
Authorization code flow
- Client redirects user to
{issuer}/authorizewithresponse_type=code,client_id,redirect_uri,scope, and optionallycode_challenge+code_challenge_method=S256. - Your app authenticates the user, then calls
oidc.authorize({ ...params, userId })to issue a code. - Client exchanges the code at
{issuer}/tokenforaccess_token,id_token, andrefresh_token. - Client can refresh tokens using
grant_type=refresh_token. Refresh tokens rotate on each use.
PKCE with
S256 is supported. If the authorization request includes a code_challenge, the token request must include the matching code_verifier. Authorization codes are single-use and expire after 10 minutes by default.Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /.well-known/openid-configuration | Discovery document |
| GET | /.well-known/jwks.json | Public signing keys |
| GET | /authorize | Authorization endpoint |
| POST | /token | Token endpoint |
| GET/POST | /userinfo | UserInfo endpoint |
| POST | /register | Dynamic client registration |