Authentication
Learn about Cartly's authentication methods: Public API, Session, JWT, and OAuth 2.0.
Authentication Methods
| Method | Use Case | Auth Header |
|---|---|---|
| Public (none) | Storefront API — products, collections, search | X-Shop-ID: {shop_id} |
| Session Cookie | Customer accounts — orders, addresses, wishlist | __session cookie |
| JWT Bearer | Admin panel — product management, order processing | Authorization: Bearer {token} |
| OAuth 2.0 | Third-party apps — marketplace integrations | Authorization: Bearer {access_token} |
OAuth 2.0 Flow
Cartly implements the standard Authorization Code flow per RFC 6749:
- Register your app — Create an OAuth app in the Cartly admin with redirect URIs and requested scopes
- Authorization request — Redirect merchant to
/oauth/authorizewith a PKCEcode_challenge(S256, required) - User consent — Merchant approves requested permissions
- Token exchange — Exchange authorization code for access + refresh tokens
- API access — Use access token in Bearer header
Rules worth knowing
- PKCE —
code_challenge= base64url(SHA-256(code_verifier)) without=padding,code_challenge_method=S256;plainis refused at the token exchange. - Scopes — space-separated. Names Cartly doesn't know are dropped. Request only scopes registered for your app: a registered-scope mismatch makes the merchant's approval fail (the consent page shows an error) and your
redirect_urigets no callback. - Refresh tokens rotate — each
refresh_tokengrant returns a new access token AND a new refresh token; store the new refresh token, the old one is revoked.
Marketplace Install
When a merchant installs your app from the Cartly marketplace, Cartly sends them to the Install URL set in your app settings (https, no query string). Cartly cannot start OAuth for you, because it never has your PKCE code_verifier: your app starts the flow. An app without an Install URL is installed, and the merchant connects it from your own site.
The request carries shop (the storefront host, e.g. my-shop.mycartly.pro), shop_id, install_id, timestamp (Unix seconds) and hmac: hex HMAC-SHA256, keyed with your client_secret, of all the other parameters sorted by name and joined as name=value&name=value (decoded values). Verify the hmac with a constant-time comparison and reject a stale timestamp.
Then send the merchant to /oauth/authorize with your own state and PKCE code_challenge. You can also forward install_id: the consent page then offers only the shop the app was installed on, and Cartly refuses the authorization if the ID is not your app's install on that shop.
Verify the install request
const crypto = require('crypto');
// query = the install request's URLSearchParams
function verifyInstall(query, clientSecret, toleranceSeconds = 300) {
const hmac = query.get('hmac') || '';
const message = [...query.entries()]
.filter(([key]) => key !== 'hmac')
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([key, value]) => key + '=' + value)
.join('&');
const expected = crypto.createHmac('sha256', clientSecret).update(message).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(query.get('timestamp'))) < toleranceSeconds;
return fresh && hmac.length === expected.length && crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(expected));
}OAuth Scopes
Available permission scopes for OAuth applications
| Name | Type | Required | Description |
|---|---|---|---|
| products:read | scope | No | View products and variants |
| products:write | scope | No | Create, update, and delete products |
| orders:read | scope | No | View orders and order history |
| orders:write | scope | No | Update order status and fulfillment |
| orders:own | scope | No | View only orders created by this app |
| customers:read | scope | No | View customer information |
| customers:write | scope | No | Create and update customers |
| discounts:read | scope | No | View discount codes and rules |
| discounts:write | scope | No | Create, update, and delete discounts |
| metafields:read | scope | No | View custom metafields |
| metafields:write | scope | No | Create, update, and delete metafields |
| webhooks:manage | scope | No | Manage webhook subscriptions |
| shop:read | scope | No | View shop settings and configuration |
| collections:read | scope | No | View product collections |
| collections:write | scope | No | Create, update, and delete collections |
| shipping:read | scope | No | View shipping zones and rates |
| shipping:write | scope | No | Manage shipping configuration |
| analytics:read | scope | No | View analytics and reports |
| inventory:read | scope | No | View inventory levels |
| inventory:write | scope | No | Set inventory levels (PUT /apps/api/inventory/:variant_id) |
| theme_extensions:write | scope | No | Add app blocks that render on the storefront (OAuth apps only) |
| checkout_extensions:write | scope | No | Add extensions that render during checkout (OAuth apps only) |
Code Examples
# Step 1: send the merchant's browser to (one line):
# https://cartly.pro/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=https%3A%2F%2Fyourapp.com%2Fcallback&scope=products%3Aread%20orders%3Aread&state=RANDOM_STATE&code_challenge=BASE64URL_SHA256_OF_CODE_VERIFIER&code_challenge_method=S256
# Step 2: Exchange code for token (send the code_verifier)
curl -X POST https://cartly.pro/oauth/token \
-H "Content-Type: application/json" \
-d '{"grant_type":"authorization_code","code":"AUTH_CODE","client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_SECRET","redirect_uri":"https://yourapp.com/callback","code_verifier":"CODE_VERIFIER"}'