If your app runs outside the Max AI dashboard (a standalone web app, mobile app, or portal), you need a way to identify which Max AI user is logged in. The OAuth 2.0 Authorization Code flow lets users sign in with their Max AI account and share their identity with your app.Documentation Index
Fetch the complete documentation index at: https://docs.maxcare.ai/llms.txt
Use this file to discover all available pages before exploring further.
Embedded apps (running inside the Max AI iframe) don’t need OAuth — they receive user context automatically via the App Bridge. OAuth is only for standalone/external apps.
Prerequisites
Before setting up OAuth, you need:- A developer account — Get started if you haven’t already
- A marketplace app — Create one in the developer console or via the CLI
- An API key — Generate one from the developer console under your app’s API Keys tab (see Authentication)
client_id in OAuth) is visible in the developer console on your app’s settings page.
How It Works
Redirect to Max AI
Your app sends the user to
/oauth/authorize with your client_id, redirect_uri, and a random state nonce for CSRF protection.User authenticates and consents
Max AI handles login (via Clerk), then shows a consent screen where the user reviews your app’s permissions and selects which organizations to authorize.
Redirect back with code
Max AI redirects the user to your
redirect_uri with a short-lived authorization code and the original state parameter.Exchange code for user info
Your backend calls
POST /v3/oauth/token with the authorization code and your API key. This is a server-to-server call — the code is never exposed to the browser.Setup
1. Register Redirect URIs
Add your callback URLs to the[oauth] section of your app manifest (max-ai.app.toml):
2. Redirect to Authorize
When a user wants to sign in with Max AI, redirect them to the authorize endpoint:| Parameter | Required | Description |
|---|---|---|
client_id | Yes | Your app’s slug (from the developer console) |
redirect_uri | Yes | Must exactly match a registered redirect URI |
state | Yes | Random string for CSRF protection — you must verify it matches on callback |
response_type | No | Must be code (default) |
prompt | No | Set to consent to force the consent screen even if the user previously authorized |
3. Handle the Callback
After the user approves (or denies), Max AI redirects to yourredirect_uri:
On approve:
Authorization codes expire after 10 minutes and can only be used once. Exchange them immediately.
4. Exchange the Code
Your backend exchanges the authorization code for user info by calling the token endpoint. Authenticate with your app’s API key:The token endpoint does not require the
X-Organization-Id header. The authorization code already encodes which organizations the user authorized.5. Receive User Info
The token endpoint returns the user’s identity, authorized organizations, and an OIDC-compliantid_token:
| Field | Description |
|---|---|
id_token | OIDC-compliant JWT (ES256-signed). Verify via the JWKS endpoint. |
user | The authenticated Max AI user |
authorizedOrganizations | Organizations the user selected, with their role and facilities |
6. Make API Calls
Now that you know the user and their organizations, use the organization IDs as theX-Organization-Id header when calling the Public API:
X-Organization-Id must be one of the organization IDs returned in authorizedOrganizations. Your API key provides data access; the OAuth flow provides user identity.
Code Example
Token Exchange Errors
The token endpoint returns OAuth 2.0 spec-compliant errors:error | HTTP Status | Description |
|---|---|---|
invalid_request | 400 | Missing required parameter (grant_type, code, or redirect_uri) |
unsupported_grant_type | 400 | Only authorization_code is supported |
invalid_grant | 400 | Code is invalid, expired, already used, or redirect_uri doesn’t match |
invalid_client | 401 | API key is missing, invalid, expired, or revoked |
server_error | 500 | OIDC signing is not configured on the server |
Repeat Authorization
When a user authorizes your app, the grant is remembered. On subsequent OAuth flows:- Same permissions — the user is redirected back instantly (no consent screen)
- Permissions changed — the consent screen is shown again
- Force re-consent — add
prompt=consentto the authorize URL to let users change which organizations they share
OpenID Connect
Theid_token is a standard OIDC JWT signed with ES256. You can verify it using the public key from the JWKS endpoint:
| Endpoint | URL |
|---|---|
| OIDC Discovery | GET /.well-known/openid-configuration |
| JWKS | GET /.well-known/jwks.json |
id_token contains standard OIDC claims:
| Claim | Description |
|---|---|
iss | Issuer URL (e.g., https://app.maxcare.ai) |
sub | User ID |
aud | Your app’s slug |
iat / exp | Issued at / expires at (1 hour) |
email | User’s email |
given_name | First name |
family_name | Last name |
picture | Profile image URL |
Embedded vs External Apps
| Embedded (iframe) | External (standalone) | |
|---|---|---|
| Runs inside | Max AI dashboard | Your own domain |
| User context | App Bridge SDK | OAuth flow |
| Auth method | Session token (automatic) | API key + OAuth code exchange |
| Setup | Set appUrl in manifest | Set redirect_uris in manifest |
| Use when | App is part of the clinic workflow | App has its own portal or mobile app |
