Skip to main content
OAuth 2.0 is the recommended authentication method for multi-tenant integrations. Lofty supports three grant types:
The first two are served by https://crm.lofty.com/api/user-web/oauth/token; Client Credentials is served by https://api.lofty.com/oauth/token. They differ in more than the host — see Choosing between them.

Prerequisites

You need a Developer Platform account and a registered application. Sign up at the Lofty Developer Portal.

Authorization Code flow

1

Register your application

Create a new application in the Developer Portal. Provide your app name, description, and redirect URI(s).New applications start in Development Mode — you can test the full OAuth flow without review.
2

Obtain credentials

After registration, you’ll receive a Client ID and Client Secret.
Never expose your Client Secret in client-side code, public repositories, or logs.
3

Request an access token

Exchange your credentials for an access token via the OAuth 2.0 authorization code flow.
The Authorization header uses HTTP Basic authentication: Base64-encode <CLIENT_ID>:<CLIENT_SECRET> to produce the credential string.For complete token endpoint details, see the OAuth 2.0 API Reference.
4

Authenticate requests

Pass the access token in the Authorization header:

PKCE flow

Use PKCE (RFC 7636) for public clients: SPAs, desktop apps, and command-line tools that cannot keep a client secret. A one-time code verifier proves that the app redeeming the code is the app that started the login.
If your app runs on a server and can keep its client secret, use the Authorization Code flow with the Authorization: Basic header instead. You can send PKCE parameters with it as well.
1

Create a code verifier and challenge

For every login, generate a random code_verifier (43–128 characters from A-Z a-z 0-9 - . _ ~) and a random state. Keep both in memory. Derive the challenge from the verifier:
Lofty accepts only the S256 method.
2

Send the user to the authorization page

Open this URL in the user’s browser. It is split across lines here for readability; send it as one URL with each value URL-encoded:
After the user approves, the browser is redirected to redirect_uri with code and state in the query string. If the user denies access, it is redirected there with error=access_denied instead. Check that state matches the value you sent before you use the code.
3

Exchange the code for tokens

Send the same redirect_uri you used in the authorization request. No client_secret is sent.

Redirect URIs for desktop and command-line apps

The authorization code reaches your app only through the registered redirect_uri. There is no other endpoint that returns it. A native app receives it on a loopback address (RFC 8252):
  • Listen on 127.0.0.1 and use http://127.0.0.1:<PORT>/callback as the redirect_uri.
  • Lofty compares redirect URIs exactly, including the port. Register every port your app may use in the Developer Portal. There is no wildcard port.
  • Pick a few fixed, uncommon ports and try them in order. An app can register at most five redirect URIs, so keep the list short. If none is free, or the browser runs on another machine (for example over SSH), let the user paste the callback URL from the browser’s address bar into your app.
The Lofty CLI works this way: lofty-cli auth login-browser listens on the first free port of its registered set and falls back to a pasted callback URL. See CLI troubleshooting.

Refresh an access token

Access tokens from the Authorization Code and PKCE flows last 10 days. Exchange the refresh token for a new pair before the access token expires — the user does not need to sign in again.
PKCE apps leave out the Authorization header and send -d "client_id=<CLIENT_ID>" instead. Use the same client ID the user authorized. A successful response:
Every refresh replaces both tokens. The access token and the refresh token you sent stop working immediately. Save the new refresh token before you use the new access token — if you lose it, the user has to authorize your app again.If several processes or servers share one authorization, let only one of them refresh. A second refresh with the old refresh token fails, and two refreshes that race each other can leave one process holding a pair that was already replaced.
  • The refresh token lasts 180 days, counted from the last refresh. Each refresh starts a new 180 days. Refresh at least once every 180 days and the user never has to re-authorize.
  • Refresh keeps the scopes the user approved. It does not add scopes your app gained afterwards — see Permission scopes.
  • When to refresh: track expires_in and refresh before it runs out. If a call is rejected because of its credentials, refresh once and retry the call. If the refresh itself fails, send the user through authorization again.
If the refresh token is unknown, expired, or already replaced, the response carries an error field instead of tokens — for example "error": "invalid_request" with "error_description": "refresh token not found". Check the body for error; do not rely on the HTTP status alone.

Revoked access

When a user disconnects your app, Lofty deletes the tokens for that user and your app. When your app is deactivated, Lofty deletes all of its tokens. Calls and refreshes with those tokens fail, and the user has to authorize your app again.

Client Credentials flow

For server-to-server integrations where there is no browser to send a user to. Instead of a user approving your app, the account holder creates an API Key in their Lofty CRM (Settings → Integrations → API Keys) and gives it to you. You exchange it, together with your app credentials, for a short-lived access token.
This endpoint is not the one the other two flows use. Different host, JSON body instead of form fields, and credentials in the body instead of an Authorization header. Sending one flow’s request shape to the other endpoint fails with a message that does not point at the mismatch.
A successful response:
The token is prefixed oat_, lasts 2 hours, and carries no refresh token — mint a new one when it expires. Send it as Authorization: Bearer <ACCESS_TOKEN>, the same as any other access token.
The token’s scope comes from the API Key, not from your app. An exchanged token can reach exactly the endpoints the account holder selected when creating their key. Permissions your app is registered for but the key does not carry are refused; permissions the key carries are reachable whether or not your app lists them.So an integration can be configured correctly on the Developer Portal and still get 403 on every call, simply because the key it was given is narrower. When a call is refused, check the key’s permissions first.

Choosing between them

Permission scopes

Calling an endpoint a token is not scoped for returns HTTP 403. The body differs by grant type, because the two are checked against different records:
Both mean the same thing — the call is outside the token’s scope — but they point at different places to fix it. See Error codes.
A token’s scopes are fixed when the user authorizes your app. The token keeps the scopes the user approved through every refresh, and every call is checked against both those scopes and your app’s current scopes.
  • Adding scopes does not break existing connections. Their tokens keep working for the endpoints they already had, but calls to the new endpoints return 403 (200100) until the user authorizes your app again. Ask existing users to re-authorize after you add a scope.
  • Removing scopes applies to every token. Calls to the removed endpoints start returning 403 (200100), which can take up to about 30 minutes to reach every token.

App lifecycle

Updating a production app

Once in production, edits require review before taking effect. Your app continues operating with the current approved configuration during review. Non-breaking changes — app name, description, redirect URIs. Existing connections are unaffected. Adding scopes — existing connections keep working with the scopes they have. Only users who authorize your app again get the new scopes. Notify users before you submit, so they know to re-authorize. Removing scopes — applies to every existing connection once the edit is published. Calls to the removed endpoints return 403.
No. Edit controls are locked during review. Cancel the pending edit first if you need to make urgent changes.
Your app continues operating with its current configuration. You’ll receive the decline reason via email and can resubmit after making adjustments.