نقلة
Docs menuAccess tokens and refresh

Access tokens and refresh

العربية

Your app reaches a store's data with a short access token, and keeps access with a refresh token that is replaced each time it is used.

Keys and tokens

KeyStarts withLifetimeUse
App idapp_…PermanentPublic, sent in the consent link.
App secretnqs_…Until rotatedSecret, on your server only, to ask for tokens.
Webhook secretnqw_…Until rotatedSecret, to verify notification signatures.
Authorization codenqc_…10 minutesComes back with the merchant, used once.
Access tokennqa_…60 minutesSent with every API request.
Refresh tokennqr_…30 daysAsks for a new access token, used once.

Never put the app secret or the webhook secret in a mobile app or a browser page. If one leaks, rotate it at once from the app page: the old one stops immediately.

Asking for tokens

Your server authenticates with an Authorization: Basic header, or by sending client_id / client_secret in the request body.

cURL
curl -X POST "https://naqllah.com/oauth/token" \
  -u "$NAQLLAH_CLIENT_ID:$NAQLLAH_CLIENT_SECRET" \
  -d grant_type=authorization_code \
  -d code="$CODE" \
  -d redirect_uri=https://your.app/callback \
  -d code_verifier="$CODE_VERIFIER"
PHP
<?php
$ch = curl_init('https://naqllah.com/oauth/token');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD => getenv('NAQLLAH_CLIENT_ID') . ':' . getenv('NAQLLAH_CLIENT_SECRET'),
    CURLOPT_POSTFIELDS => http_build_query([
        'grant_type' => 'authorization_code',
        'code' => $_GET['code'],
        'redirect_uri' => 'https://your.app/callback',
        'code_verifier' => $_SESSION['pkce_verifier'],
    ]),
]);
$token = json_decode(curl_exec($ch), true);
// $token['access_token'], $token['refresh_token'], $token['expires_in']
Node.js
const basic = Buffer.from(
  `${process.env.NAQLLAH_CLIENT_ID}:${process.env.NAQLLAH_CLIENT_SECRET}`,
).toString('base64');

const res = await fetch('https://naqllah.com/oauth/token', {
  method: 'POST',
  headers: { Authorization: `Basic ${basic}` },
  body: new URLSearchParams({
    grant_type: 'authorization_code',
    code: code,
    redirect_uri: 'https://your.app/callback',
    code_verifier: codeVerifier,
  }),
});
const token = await res.json();
Python
import os, secrets
import requests

res = requests.post(
    "https://naqllah.com/oauth/token",
    auth=(os.environ["NAQLLAH_CLIENT_ID"], os.environ["NAQLLAH_CLIENT_SECRET"]),
    data={
        "grant_type": "authorization_code",
        "code": code,
        "redirect_uri": "https://your.app/callback",
        "code_verifier": code_verifier,
    },
    timeout=10,
)
token = res.json()
200 · JSON
{
    "access_token": "nqa_\u2026",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "nqr_\u2026",
    "scope": "store.read orders.read webhooks.read",
    "store": {
        "id": 1042,
        "uuid": "9b2f6c1e-4d3a-4f7b-a1c2-5e8d0f9a7b31"
    }
}

An access token lasts 60 minutes, a refresh token 30 days, and a code 10 minutes. Tokens are bound to one store and one install.

Using the access token

Send it with every request in Authorization: Bearer nqa_…. The store comes from the token itself: one token, one store, one install.

Refreshing

A refresh token works once and is replaced by a new one. If an old refresh token is used again, every token of that grant is revoked.

cURL
curl -X POST "https://naqllah.com/oauth/token" \
  -u "$NAQLLAH_CLIENT_ID:$NAQLLAH_CLIENT_SECRET" \
  -d grant_type=refresh_token \
  -d refresh_token="$REFRESH_TOKEN"
PHP
<?php
$ch = curl_init('https://naqllah.com/oauth/token');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD => getenv('NAQLLAH_CLIENT_ID') . ':' . getenv('NAQLLAH_CLIENT_SECRET'),
    CURLOPT_POSTFIELDS => http_build_query([
        'grant_type' => 'refresh_token',
        'refresh_token' => $refreshToken,
    ]),
]);
$token = json_decode(curl_exec($ch), true);
// $token['access_token'], $token['refresh_token'], $token['expires_in']
Node.js
const basic = Buffer.from(
  `${process.env.NAQLLAH_CLIENT_ID}:${process.env.NAQLLAH_CLIENT_SECRET}`,
).toString('base64');

const res = await fetch('https://naqllah.com/oauth/token', {
  method: 'POST',
  headers: { Authorization: `Basic ${basic}` },
  body: new URLSearchParams({
    grant_type: 'refresh_token',
    refresh_token: refreshToken,
  }),
});
const token = await res.json();
Python
import os, secrets
import requests

res = requests.post(
    "https://naqllah.com/oauth/token",
    auth=(os.environ["NAQLLAH_CLIENT_ID"], os.environ["NAQLLAH_CLIENT_SECRET"]),
    data={
        "grant_type": "refresh_token",
        "refresh_token": refresh_token,
    },
    timeout=10,
)
token = res.json()
  • Refresh shortly before the access token expires, or when you get 401 invalid_token.
  • Save the new refresh token before you use the new access token: the old one no longer works.
  • If two of your servers refresh at the same time, only one succeeds. Refresh in one place, under a lock.

Revoking

Revoke an access or refresh token when you are done with it. A merchant uninstalling your app revokes every token automatically.

Storing tokens

  • Encrypt tokens at rest, separately for each store.
  • Never write tokens or secrets in logs, error reports or links.
  • Delete a store's tokens when you receive app.uninstalled.

Version v1.0.0 Changelog Service status openapi-v1.json Support