Skip to main content
Every Leaf API request uses Authorization: Bearer <token>. There are two ways to get that token:
  • OAuth2 (recommended) — get an access_token from the Leaf token endpoint, put it in the Bearer header, and call https://api-v2.withleaf.io. Server-to-server integrations use an API client (client_id and client_secret) with the client credentials grant. Integrations that sign in with the API owner email and password use the password grant, and exchange the refresh_token for a new access token without re-sending the password.
  • /authenticate — send your API owner email and password to get an id_token. There is no refresh token; when it expires, authenticate again. Call https://api.withleaf.io.
For conceptual background, see Authentication.

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.
Never expose credentials in browser or mobile clients, and store client secrets, access tokens, and refresh tokens securely.

Client credentials grant

Use this grant for server-to-server integrations. An API client belongs to one API owner, and its client ID starts with leaf-api-. Leaf provisions it and gives you the client_id and client_secret.
  • API clients do not accept the password grant: that request returns 400 unauthorized_client.
  • A new API client 403s until Leaf assigns its roles; the grant itself does not copy the API owner’s roles.
The response has no 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 a client_id that allows this grant.

Refresh token grant

Exchange a refresh token for a new access token without re-sending credentials.

Response

Use the 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.
When using OAuth2, send API requests to the new base URL https://api-v2.withleaf.io instead of https://api.withleaf.io.For example, Get All Leaf Users: https://api-v2.withleaf.io/services/usermanagement/api/users
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 the Authorization header of every API request:

Error responses

Last modified on November 3, 2026