Authorization: Bearer <token>. There are two ways to get that token:
- OAuth2 (recommended) — get an
access_tokenfrom the Leaf token endpoint, put it in the Bearer header, and callhttps://api-v2.withleaf.io. Server-to-server integrations use an API client (client_idandclient_secret) with the client credentials grant. Integrations that sign in with the API owner email and password use the password grant, and exchange therefresh_tokenfor a new access token without re-sending the password. /authenticate— send your API owner email and password to get anid_token. There is no refresh token; when it expires, authenticate again. Callhttps://api.withleaf.io.
OAuth2 token endpoint
POST https://auth.withleaf.io/realms/leaf/protocol/openid-connect/token
Requests use Content-Type: application/x-www-form-urlencoded. Three grant types are supported: client credentials, Username/Password, and refresh token.
Client credentials grant
Use this grant for server-to-server integrations. An API client belongs to one API owner, and its client ID starts withleaf-api-. Leaf provisions it and gives you the client_id and client_secret.
- API clients do not accept the password grant: that request returns
400unauthorized_client. - A new API client 403s until Leaf assigns its roles; the grant itself does not copy the API owner’s roles.
refresh_token. The access token lasts 300 seconds (expires_in). Request a new token with the same grant before it expires. Calls made with the token act as the client’s API owner, limited to the permissions Leaf grants the client.
Username/Password Grant
Uses your API owner credentials together with aclient_id that allows this grant.
Refresh token grant
Exchange a refresh token for a new access token without re-sending credentials.Response
access_token in the Authorization: Bearer <token> header of every API request. When it expires, use the refresh token grant to obtain a new one.
Token lifetimes (
expires_in, refresh_expires_in) are configured per client; the values above are examples and may differ for yours.Error responses
Legacy /authenticate method
Email and password for an id_token. No refresh token. API calls go to https://api.withleaf.io.
POST /authenticate
Base URL
Request body
Token duration
When a token expires, request a new one from the same endpoint. There is no refresh token flow.
Request
Response
Using the token
Include the token in theAuthorization header of every API request:

