Clickmax Apps OAuth reference
The OAuth 2.0 and OpenID Connect contract a Clickmax App's server uses to receive installations and call the Clickmax API. The app is created in Settings > Connections, My apps tab (see How do I create a Clickmax App in My apps?); the full flow is in How does a Clickmax App get installed and act in a workspace?.
Addresses
App credentials
Authorization request
Parameters of GET /oauth2/authorize:
Scopes
An app accepts only these scopes. Any other scope comes back with error=invalid_scope.
With install, Clickmax asks the person to sign in, shows Where to install … and then Install …. Without install, there is no workspace choice (see Sign in with Clickmax).
Return to the redirect_uri
When client_id or redirect_uri does not match the app, Clickmax shows an error page and does not return to the redirect_uri.
Code exchange
POST /oauth2/token, with HTTP Basic and an application/x-www-form-urlencoded body:
The code is valid for 10 minutes and once.
The response has no refresh_token. Installing again in the same workspace returns the same installation_id.
Installation token
POST /oauth2/token, with HTTP Basic and an application/x-www-form-urlencoded body:
There is no refresh_token. To renew, request another token with the same installation_id, at any time. The installation_id does not expire: it is valid while the installation exists.
The TypeScript SDK requests the token on the first call, reuses it until one minute before it expires and requests another when the API answers 401.
Install from Clickmax
An install can also start on Clickmax, without an authorization request from the app: through the install link of an Unlisted app, through the Install button in My apps, or when a Private app is created, which installs it in the workspace that created it. This path has no code to exchange: the app receives the installation_id at the Setup URL or finds it in the installation list.
Optional parameters of the install link:
After the click on Install or Update permissions, if the app has a Setup URL, the browser goes there with these parameters, added to the query the URL already has:
The Setup URL follows the rules of the Redirect URLs (https, or http on localhost, 127.0.0.1 or [::1], no fragment), up to 2048 characters. The install from the app's system (install in the authorization request) does not go through it.
Anyone can open the Setup URL with a made-up installation_id and workspace_id. Before using the ID, read the installation at GET /apps/installations/<installation_id> with the app's credentials: only an active installation of your app answers, and the workspace in the response is the one that counts. Do not tie the installation to the person signed in to your system just because they arrived through the Setup URL; to tie an installation to an account in your system, use the install from the app's system, with state.
Installation list
With the app's credentials, no installation token. HTTP Basic authentication with the client ID and secret, as at the token endpoint.
GET https://login.clickmax.io/api/auth/apps/installations
The response holds the app's active installations, oldest first, suspended ones included. Removed installations and those of disabled workspaces are absent.
GET https://login.clickmax.io/api/auth/apps/installations/<installation_id> returns one installation in the same format as the items of data.
Errors come in the token endpoint's format: { "error": "…", "error_description": "…" }. In the TypeScript SDK, use listInstallations and getInstallation (see Read the app's installations).
Calling the API
Send the installation token on every request to https://mcp.clickmax.io/api/v0:
An expired token, or one of an installation that is no longer valid, gets 401 with the code unauthorized. Request a new token and retry once. If the token request fails with invalid_grant, the installation is no longer valid.
Every key and app of a workspace shares the same rate limit. Each source IP also has a limit of its own, counted across every workspace it calls: a server that serves many installations shares that limit among them. In Max Design server routes, that limit counts per project. Error format in Errors.
End of access
Missing permissions
An API operation may need more than one permission. Searching leads by filters, for example, also needs View on Lists and segments. When a permission is missing, the operation fails with type permission, code missing_permission and the capability field naming the missing permission. The granted and pending permissions of each installation are in grantedCapabilities and pendingCapabilities of the installation list.
Changing the Requested permissions in My apps does not change what each installation already has. Anything new stays pending until someone in the workspace approves it in Installed apps, and the approver grants only what they can do. Whatever leaves the request is removed from the installations. While a permission is pending, operations that depend on it fail with missing_permission.
Sign in with Clickmax
To let people sign in to your system with their Clickmax account, use any OpenID Connect library with discovery at https://login.clickmax.io/api/auth/.well-known/openid-configuration and the scopes openid profile email, without install. There is no workspace choice: the screen is Sign in to … with Clickmax, with the Continue button. The ID token and UserInfo carry sub and, depending on the scopes, email, email_verified and name.
ID tokens are signed with EdDSA (Ed25519). Libraries that only accept RS256 need that algorithm enabled. Sign in with Clickmax grants no API access: the v0 API refuses the token of this flow.
Apps inside Clickmax
An app with an Address in Clickmax opens inside the panel, on a https://app.clickmax.io/<workspace>/apps/<app slug> page, for whoever has the View and open installed apps permission in a workspace where the app is installed and active. The panel loads the Address in Clickmax in an iframe and talks to it through the bridge. The app never gets the person's session: it asks the panel for a session token, and the app's server exchanges that token for an access token that acts on the person's behalf.
Bridge with the panel
Messages are JSON objects { type, v: 1, ... } sent with postMessage. The panel accepts messages only from the iframe whose origin is the Address in Clickmax origin. The app must accept only messages whose event.origin equals the panel's origin, and send its own with that origin as the target.
Send the session token to your server in the x-clickmax-session-token header. Inside the iframe, the browser blocks your site's cookies, and on Max Design sites the Authorization and Cookie headers do not reach the /api routes in the preview.
Session token exchange
POST https://login.clickmax.io/api/auth/oauth2/token, with HTTP Basic (client ID and secret, as in the other token requests) and an application/x-www-form-urlencoded body:
There is no refresh_token. When the access token expires, ask the panel for a new session token and exchange it again. Use the workspace_id and installation_id from the response, not the ones the app screen sends to your server.
Apps built in Max Design
In a Max Design project with .clickmax/app.json, publishing creates the app, saves APP_CLIENT_ID and APP_CLIENT_SECRET to the project's Secrets and sets the published address as the Address in Clickmax. An exchange coming from that project's server also works without the secret: Clickmax recognizes where the call comes from and authenticates the project's app. In that case, send client_id in the body, without Authorization. The project preview exchanges as the same app.
The project gets two files that already do all of this: src/lib/clickmax-app.ts, the bridge in the page, and src/server/clickmax.ts, the exchange and the API calls. The panel, login and API origins reach the server in CLICKMAX_PANEL_ORIGIN, CLICKMAX_LOGIN_BASE_URL and CLICKMAX_API_BASE_URL, with the values of the environment the site runs in.
On behalf of the person
With the exchanged token, each API v0 call acts as the person through the app. The operation goes through only if the installation was granted the permission and the person can do it in the workspace. Clickmax checks both on every call: a change to the person's role or to the installation's permissions applies on the next one. Being the workspace owner gives the app nothing beyond what the installation was granted. History shows the person and the app.
When either permission is missing, the API answers as in Missing permissions. For work with no person behind it, such as background tasks, keep using the installation token.
For permissions with an "everyone's" version, such as opportunities, scheduling and conversations, a person who only has their own version sees through the app only the records assigned to them, as in the panel.
Example
TypeScript, fetch only, no framework. On the screen the panel loads:
On your server, the route that receives the session token, exchanges it and calls the API (tags/list, which needs View on Tags for both the installation and the person):
What apps cannot do yet
With the installation token, an app acts with the permissions of its installation, and no person is attached to its calls. In this version, apps cannot use these resources through the API, even with the permission granted:
Everyone's permissions
No record is assigned to an app. For the actions below, the permission without "everyone's" reaches only the records assigned to the caller, so it reaches no records when the caller is an app. Grant the everyone's variant of each of these actions, such as View (everyone's):
Without the variant, the API refuses the operation with type permission.
Creating an opportunity, or editing and deleting one at a time, works without "everyone's", but needs View (everyone's) on Opportunities. Bulk actions on opportunities also need Edit (everyone's) or Delete (everyone's). Creating, editing or deleting a calendar appointment works without "everyone's", but needs View (everyone's) on Calendar.
No app or API key can hold the Apps, API and MCP keys, People with access (Manage) and Account details (Manage) permissions. They show as locked on the app's permission screen.
API keys created with chosen permissions have the same limits. See Clickmax API authentication.
Complete example
The public clickmax-apps-sample repository shows the install from the app's system end to end, in TypeScript with the SDK. Below, a Node.js 20 or newer server, with no dependencies, covering the connect button, the return, the code exchange, the installation token request and one API call (tags/list, which needs View on Tags). Register http://127.0.0.1:3000/clickmax/callback in the app's Redirect URLs, set CLICKMAX_CLIENT_ID and CLICKMAX_CLIENT_SECRET and run node server.mjs. On your deployed server, keep pending and installations in your database and mark the cookie Secure.
With the TypeScript SDK, exchangeInstallCode does the code exchange and new Clickmax({ clientId, clientSecret, installationId }) handles the installation token. See Use Clickmax App credentials.
Related
- Clickmax API: base address, errors and rate limit.
- How to use the Clickmax TypeScript SDK
- How do I create a Clickmax App in My apps?
- How do I manage the apps installed in a workspace?
- Roles and permissions