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
| Key | Starts with | Lifetime | Use |
|---|---|---|---|
| App id | app_… | Permanent | Public, sent in the consent link. |
| App secret | nqs_… | Until rotated | Secret, on your server only, to ask for tokens. |
| Webhook secret | nqw_… | Until rotated | Secret, to verify notification signatures. |
| Authorization code | nqc_… | 10 minutes | Comes back with the merchant, used once. |
| Access token | nqa_… | 60 minutes | Sent with every API request. |
| Refresh token | nqr_… | 30 days | Asks 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 -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
$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']
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();
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()
{
"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 -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
$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']
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();
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