OAuth and MCP
Build an OAuth app
Register an OAuth 2 client with PKCE so teammates in any dimmi workspace can connect your app to the REST API or MCP.
Your app registers dynamically, sends a teammate to dimmi for approval, and receives tokens that work with both the REST API and the MCP server.
Discovery metadata lives at https://trydimmi.com/.well-known/oauth-authorization-server (or on your self-hosted URL).
Register your client
Section titled “Register your client”curl https://trydimmi.com/oauth/register \ -H "Content-Type: application/json" \ -d '{ "client_name": "Acme Reports", "redirect_uris": ["https://acme.example.com/oauth/callback"], "application_type": "web", "token_endpoint_auth_method": "client_secret_basic", "scope": "conversations:read contacts:read offline_access" }'The 201 response returns client_id (dmi_oci_...) and, for confidential clients, a client_secret (dmi_ocs_...) shown only once.
| Field | Rules |
|---|---|
client_name |
1 to 100 characters, displayed on the consent screen. |
redirect_uris |
1 to 10 exact URIs: https, http on loopback (any port), or a custom app scheme. |
application_type |
native (default) or web (web requires public https redirect URIs). |
token_endpoint_auth_method |
none (default, public client), client_secret_basic, or client_secret_post. |
grant_types |
authorization_code and refresh_token (default: both). |
scope |
Space-separated max scopes your app can request (default: all scopes). |
Scopes match API token abilities (except system:read and system:write), plus offline_access (accepted and ignored). Any :write scope automatically includes :read.
Each IP can register up to 20 clients per hour. The consent screen tells teammates that dimmi cannot verify who built dynamically registered apps.
Send a teammate to authorize
Section titled “Send a teammate to authorize”import { createHash, randomBytes } from "node:crypto";
const verifier = randomBytes(32).toString("base64url");const challenge = createHash("sha256").update(verifier).digest("base64url");const state = randomBytes(16).toString("base64url");
const url = new URL("https://trydimmi.com/oauth/authorize");url.search = new URLSearchParams({ response_type: "code", client_id: "<client_id>", redirect_uri: "https://acme.example.com/oauth/callback", scope: "conversations:read contacts:read offline_access", state, code_challenge: challenge, code_challenge_method: "S256",}).toString();
console.log({ verifier, state, url: url.toString() });Save verifier and state in the user’s session and redirect them to url. Only PKCE S256 is supported.
The teammate picks a workspace and can uncheck scopes. dimmi redirects back with code, state, and iss (or error=access_denied).
Exchange the code for tokens
Section titled “Exchange the code for tokens”Authorization codes expire after 1 minute and work once.
curl https://trydimmi.com/oauth/token \ -u "<client_id>:<client_secret>" \ -d grant_type=authorization_code \ -d code=<code> \ -d redirect_uri=https://acme.example.com/oauth/callback \ -d code_verifier=<verifier>{ "access_token": "dmi_oat_...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "dmi_ort_...", "scope": "conversations:read contacts:read offline_access"}Public clients pass client_id in the form body without a secret. Check the returned scope to see what the teammate approved.
Send the token as Authorization: Bearer <access_token>. Requests run as that teammate in the chosen workspace and respect their workspace role.
Refresh access tokens
Section titled “Refresh access tokens”curl https://trydimmi.com/oauth/token \ -u "<client_id>:<client_secret>" \ -d grant_type=refresh_token \ -d refresh_token=<refresh_token>- Rotating tokens: every refresh issues a new refresh token and invalidates the old one. Save the new token before using the access token.
- Replay protection: reusing a code or refresh token that was already spent revokes the entire grant and all its tokens.
- Inactivity expiry: refresh tokens expire after 90 days unused.
Revoke tokens
Section titled “Revoke tokens”curl https://trydimmi.com/oauth/revoke \ -u "<client_id>:<client_secret>" \ -d token=<token>Revoking a refresh token ends the full grant; revoking an access token ends only that token. Both return 200.
Teammates can also revoke access anytime in Settings → Connected apps, and tokens stop working if the teammate leaves the workspace.
Error format
Section titled “Error format”/oauth/token, /oauth/revoke, and /oauth/register return errors as {"error": "invalid_grant", "error_description": "..."}. Max request body size is 16 KB.