REST API
Authenticating the API with OAuth 2
Call Doclift's REST API with an OAuth 2 access token instead of an API key: sandbox and production resources, authorization code with PKCE, refresh, revocation and webhook signing.
The REST API accepts two credentials: the X-Api-Key header, described in
API basics, and an OAuth 2 access
token sent in Authorization: Bearer. The first suits your own server. The
second suits an application that acts on behalf of several Doclift
users, each authorizing access with their own account.
Endpoints, bodies and responses are the same whichever credential you use. Only authentication changes.
Getting a client
Registering an OAuth client is not self-service: the Doclift team does it. Write to [email protected] with:
- the name of your application;
- your redirect URIs, over HTTPS.
http://localhostandhttp://127.0.0.1are accepted for development.
Doclift then hands you, once, three values: the client_id, the
client_secret and the webhook_secret. Keep them as you would an API
key: they are not shown again. The client is confidential: the
client_secret must never leave your server. Each redirect URI must match
exactly one of those declared at registration.
Presenting the token
curl https://app.doclift.io/api/v1/templates \
-H "Authorization: Bearer <access_token>"
| Situation | Response |
|---|---|
| X-Api-Key | The key applies, even if an Authorization header comes with it. |
| Authorization: Bearer | The token applies. |
| No credential at all | 403 with {"error": "Please add an 'X-Api-Key' HTTP header."}. |
| Invalid, expired or revoked token | 401 , body {"error": "invalid_token"}, with a WWW-Authenticate header. |
| Production token, organization without the production right | 403 with a JSON body. |
The 401 carries the address of the resource metadata, which an OAuth
client reads to start the authorization again:
WWW-Authenticate: Bearer resource_metadata="https://app.doclift.io/.well-known/oauth-protected-resource/api/v1", scope="api"
An OAuth token does not require the workflow editor to be enabled for the organization, except on the workflows endpoints, which already require it whichever credential you use.
Resources and modes
The token is bound to a resource, and the resource sets the mode. The
URL you call changes nothing: a production token calling
/api/v1/templates runs in production.
| Mode | Resource |
|---|---|
| Sandbox | https://app.doclift.io/api/v1 |
| Production | https://app.doclift.io/api/v1/production |
Production requires the production right of the user's organization. That
right is checked on every call: a production token whose organization
has lost the right gets 403.
The scope to ask for is api. Add offline_access to receive a refresh
token.
A token bound to one resource never opens the other family. An MCP connector token (see MCP server) does not open the REST API, and a REST API token does not open the MCP server.
The flow
Doclift implements the authorization code flow with PKCE and nothing else.
- PKCE is mandatory, with the
S256method only. - The
resourceparameter is sent to/oauth/authorizeand to/oauth/token, with the exact URL of the resource. It must name a single resource. - The access token lasts 2 hours. The authorization code lasts 10 minutes.
- Refreshing rotates the token: each use issues a new one and revokes the old one at once.
1. Prepare PKCE
code_verifier=$(openssl rand -base64 48 | tr -d '=+/\n' | cut -c1-64)
code_challenge=$(printf '%s' "$code_verifier" \
| openssl dgst -sha256 -binary \
| openssl base64 -A | tr '+/' '-_' | tr -d '=')
2. Send the user to authorize access
Open this address in the user's browser. They sign in with their Doclift account, then allow or deny.
https://app.doclift.io/oauth/authorize
?response_type=code
&client_id=<client_id>
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
&scope=api%20offline_access
&resource=https%3A%2F%2Fapp.doclift.io%2Fapi%2Fv1
&state=<random-state>
&code_challenge=<code_challenge>
&code_challenge_method=S256
Doclift redirects to your redirect_uri with code and state. Compare
state with the value you sent.
3. Exchange the code
curl https://app.doclift.io/oauth/token \
--request POST \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=<code>" \
--data-urlencode "redirect_uri=https://app.example.com/callback" \
--data-urlencode "client_id=<client_id>" \
--data-urlencode "client_secret=<client_secret>" \
--data-urlencode "code_verifier=$code_verifier" \
--data-urlencode "resource=https://app.doclift.io/api/v1"
{
"access_token": "<access_token>",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "<refresh_token>",
"scope": "api offline_access",
"created_at": 1790000000
}
A code works once. Replaying it answers invalid_grant and revokes the
tokens it had issued.
The client authenticates on /oauth/token either with HTTP Basic
(Authorization: Basic base64(client_id:client_secret)), or with
client_id and client_secret in the request body.
4. Call the API
curl https://app.doclift.io/api/v1/templates \
-H "Authorization: Bearer <access_token>"
5. Refresh the token
curl https://app.doclift.io/oauth/token \
--request POST \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "refresh_token=<refresh_token>" \
--data-urlencode "client_id=<client_id>" \
--data-urlencode "client_secret=<client_secret>"
The response has the shape of step 3, with a new refresh_token.
Replace the one you store immediately: the old one is revoked, and
replaying it answers invalid_grant.
The resource parameter is optional on refresh: left out, the new
token keeps the previous token's resource. If sent, it must name a
resource the token was already granted; a different resource is refused
with invalid_target. A refresh therefore cannot change resource.
A refresh token unused for 90 days is revoked: refreshing it then
answers invalid_grant. The authorization has to be started again (step 2),
since no new token can be obtained without it.
error | Cause |
|---|---|
| invalid_grant | Code or refresh token already used or revoked, or a code_verifier that does not match. |
| invalid_target | resource missing from the authorization, or a resource this client is not allowed to ask for. |
Metadata
A generic OAuth client discovers the addresses from these documents:
| Address | Content |
|---|---|
| /.well-known/oauth-authorization-server | The authorization server's endpoints. |
| /.well-known/oauth-protected-resource/api/v1 | The REST API sandbox resource. |
| /.well-known/oauth-protected-resource/api/v1/production | The REST API production resource. |
Revoking a connection
Each user sees and revokes the connections they authorized on the
Connections page of their account, at /account/connections.
Revocation removes access immediately.
An OAuth connection and an API key are two separate credentials: revoking or deactivating a key does not affect OAuth connections, and the other way round.
Webhooks
An OAuth caller has no webhook URL configured on an application: there is
no dashboard for it. The URL is given per request, with callback_url
in the document_request object of the body of
POST /api/v1/document_requests. This field is not specific to OAuth: it is
read for any caller (see
The fields).
The X-Doclift-Signature is sha256=<hex>, the HMAC-SHA256 of the raw
request body, keyed with the client's webhook_secret. For an application
that holds an API key it is still computed with the API key, unchanged.
See
Verifying the signature.
Limits
A caller that authenticates with a Bearer token, the /oauth/token
endpoint and the MCP connector are limited in number of requests. Beyond
the limit, the response is a 429 with {"error": "rate_limited"} and a
Retry-After header: wait that delay before replaying. No value is
published, and a call authenticated with X-Api-Key is never counted by
this limit.
Next
API basics
Base URL, environments, response codes and errors.
MCP server
The remote connector, which uses the same authorization server.