Quran Foundation User APIs OAuth2 Quickstart
Audience: Developers adding signed-in Quran.com user features such as bookmarks, collections, notes, reading progress, goals, and preferences.
Prerequisites: An app and pre-live client_id from Developer Console, plus at least one registered redirect URI. A Backend/server app also receives a one-time client_secret; a Frontend or mobile app does not.
Recommended flow: Hosted login + PKCE in your app, followed by the exchange and refresh flow for the app type selected in Developer Console.
Outcome: One User API call with an OAuth2 access_token, using the runtime boundary that matches your app type.
Use this quickstart after choosing User APIs from the Developer Journey. It gets you to the architecture selected in Developer Console and one successful signed-in User API call.
Use the OAuth2 tutorial when you need the full manual flow, client-type details, token exchange examples, refresh handling, scopes, and troubleshooting.
Production vs Pre-live
If you are testing User APIs in pre-live, keep the entire flow in pre-live.
- Use the Pre-live User APIs reference when testing pre-live endpoints.
- Use prelive.quran.com for auth paths and auth-backed user data checks.
- Use prelive.quranreflect.org for Quran Reflect paths and data checks.
- Do not mix production login state, production user data, or production docs with pre-live testing.
Recommended Architecture
- Let your app or website open the Quran Foundation hosted login screen.
- Generate PKCE,
state, andnoncein the app or browser client. - After login, receive the authorization
codeat your redirect URI. - Send
code + code_verifier + redirect_urito your backend. - Keep
QF_CLIENT_SECRETon the backend and perform/oauth2/tokenexchange and refresh there. - Have your backend or serverless proxy call User APIs with
x-auth-tokenandx-client-id.
The SDK example below follows this confidential backend/server pattern. Direct browser calls from third-party origins may be rejected by CORS or origin allowlist checks.
If you selected Frontend or mobile app in Developer Console, the client is public: exchange the code in the app using PKCE, then refresh with client_id and no client_secret. See the manual OAuth2 tutorial for that flow; the server SDK example below is for a confidential Backend/server app.
First SDK Request
Once your backend has a signed-in user session, the SDK can call User APIs from server code:
import { createServerClient } from "@quranjs/api/server";
const serverClient = createServerClient({
clientId: process.env.QF_CLIENT_ID!,
clientSecret: process.env.QF_CLIENT_SECRET!,
services: {
gatewayUrl: "https://apis-prelive.quran.foundation",
oauth2BaseUrl: "https://prelive-oauth2.quran.foundation",
},
userSession: {
accessToken: session.accessToken,
refreshToken: session.refreshToken,
expiresAt: session.expiresAt,
},
});
const bookmarks = await serverClient.auth.v1.bookmarks.list({ first: 10 });
This example explicitly uses pre-live so it matches a newly created Console app. After production permissions are granted, switch the credentials and both service URLs to production together. In production, add SDK storage so refreshed user sessions are persisted in your server-side session store. Continue with the JavaScript SDK guide for installation, runtime configuration, and endpoint-specific SDK examples.
First Raw HTTP Request
Raw HTTP works too. Once your backend has an access_token, it can call a User
API endpoint like this:
const accessToken = session.accessToken; // OAuth2 access token stored server-side
const response = await fetch(
"https://apis-prelive.quran.foundation/auth/v1/bookmarks",
{
headers: {
"x-auth-token": accessToken,
"x-client-id": process.env.QF_CLIENT_ID,
},
}
);
if (!response.ok) {
const errorBody = await response.json().catch(() => null);
const errorType = errorBody?.type ? ` (${errorBody.type})` : "";
throw new Error(`User API request failed: ${response.status}${errorType}`);
}
const bookmarks = await response.json();
For web apps, SDK or raw HTTP requests are usually made by your backend or
serverless proxy, not by page JavaScript. Cookies are for your app's own
session; x-auth-token and x-client-id are the headers your server sends to
Quran Foundation.
Handle API Errors
Always check the response status before using the JSON payload. User API errors generally return a JSON body with message, type, and success: false; endpoint reference pages show the exact shape for each operation.
| Status | What it usually means | What to do |
|---|---|---|
400 or 422 | Invalid request, missing required parameters, or validation failure | Fix the request or form data before retrying. |
401 | Missing, expired, or invalid user access_token | If you have a refresh_token, refresh once and retry once. If it still fails, require the user to sign in again. |
403 | Missing scope/permission, wrong environment, or a browser/origin restriction | Route web calls through your backend, confirm the token environment, and request the correct scopes. |
429 | Rate limit exceeded | Back off and retry later. Prefer exponential backoff with jitter. |
500, 502, 503, 504 | Temporary server or upstream failure | Retry with bounded backoff, then surface a temporary failure. |
Do not log access_token, refresh_token, id_token, authorization codes, code_verifier, or QF_CLIENT_SECRET while handling failures. For detailed OAuth2 and User API troubleshooting, see Common Issues & Troubleshooting.
Platform Guides
| Platform | Recommended pattern | Start here |
|---|---|---|
| Web | Frontend or mobile app: in-app public exchange. Backend/server app: server-side session and exchange. | Web integration example |
| React Native | Frontend or mobile app: in-app public exchange. Backend/server app: backend exchange. | React Native guide |
| Android | Frontend or mobile app: AppAuth public exchange. Backend/server app: backend exchange. | Android guide |
| iOS | Frontend or mobile app: AppAuth public exchange. Backend/server app: backend exchange. | iOS guide |
| Full OAuth2 and OIDC details | Step-by-step flow, validation, refresh, scopes, and troubleshooting | OAuth2 tutorial |
Scope And Token Details
Request only the scopes your app needs. Start with openid for identity, add offline_access when you need refresh tokens, then add feature scopes such as bookmark, collection, note, reading_session, preference, goal, or streak as needed.
Use these references for the details:
- OAuth2 Scopes for available scopes.
- OAuth2 tutorial for token exchange, refresh,
state,nonce, and troubleshooting. - OpenID Connect guide for
id_tokenclaims and identity concepts.
Next Steps
- JavaScript SDK guide if you want typed SDK clients in an existing JS/TS backend.
- OAuth2 tutorial for the full Authorization Code with PKCE flow.
- Web integration example for a working server-side implementation.
- User APIs reference for endpoint-by-endpoint API details.
Need Help?
Create and manage credentials, redirect URIs, scopes, and app type in Developer Console. If Developer Console cannot resolve the issue or you still need help, email [email protected].