تخطَّ إلى المحتوى الرئيسي

Authentication

API keys, and OAuth apps with PKCE.

API key

A key starts with cpk_live_ and is shown once, when it is created. Give it only the scopes it needs; it can be pinned to one branch and its children, and given an expiry date. Revoking it in the dashboard stops it at once.

Authorization: Bearer cpk_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

OAuth app

Register the app under «المطوّرون وواجهة API» → apps: name, redirect URIs (https only, exact match) and the scopes it asks for. You receive a client_id starting with cxa_ and a secret starting with cxs_, shown once. A private app works on your own business at once; listing it for every business needs a Cortex review.

1. Create the verifier, the challenge and a state

Node.js
import { createHash, randomBytes } from "node:crypto";

const verifier = randomBytes(32).toString("base64url");          // keep it server-side
const challenge = createHash("sha256").update(verifier).digest("base64url");
const state = randomBytes(16).toString("base64url");             // bind it to the user's session
Python
import base64, hashlib, secrets

verifier = secrets.token_urlsafe(32)                             # keep it server-side
challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode()
state = secrets.token_urlsafe(16)                                # bind it to the user's session

2. Send the owner to the consent page

https://dashboard.xodata.ninja/oauth/authorize?response_type=code
  &client_id=cxa_XXXXXXXXXXXXXXXXXXXXXXXX
  &redirect_uri=https%3A%2F%2Fyour-app.example.com%2Fcortex%2Fcallback
  &scope=orders%3Aread%20reservations%3Aread
  &state=<state>
  &code_challenge=<challenge>
  &code_challenge_method=S256

After approval the browser returns to your redirect URI with code and state. Check that state is the one you sent. A refusal returns error=access_denied with your state.

3. Exchange the code within 60 seconds

curl -X POST https://dashboard.xodata.ninja/api/oauth/token \
  -u "cxa_XXXXXXXXXXXXXXXXXXXXXXXX:cxs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
  -d grant_type=authorization_code \
  -d code=<code> \
  -d redirect_uri=https://your-app.example.com/cortex/callback \
  -d code_verifier=<verifier>
{
  "access_token": "cxat_…",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "cxrt_…",
  "scope": "orders:read reservations:read"
}

The cxat_ access token lives one hour. The cxrt_ refresh token lives 60 days and changes on every refresh. Using an old refresh token a second time revokes the whole grant, so always store the new one.

Refresh
curl -X POST https://dashboard.xodata.ninja/api/oauth/token \
  -u "<client_id>:<client_secret>" \
  -d grant_type=refresh_token \
  -d refresh_token=cxrt_…

To revoke: POST https://dashboard.xodata.ninja/api/oauth/revoke with token and the client credentials. The owner can also remove your app at any time; you then receive app.uninstalled.

There is no implicit and no client_credentials grant. PKCE (S256) and the client secret are both required, so never ship the secret in a mobile app or a browser page.