Skip to main content

Quran Foundation User APIs OAuth2 Quickstart

Quick Summary

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​

Pre-live uses a separate user stack

If you are testing User APIs in pre-live, keep the entire flow in pre-live.

Server example: Backend/server app
  • Let your app or website open the Quran Foundation hosted login screen.
  • Generate PKCE, state, and nonce in the app or browser client.
  • After login, receive the authorization code at your redirect URI.
  • Send code + code_verifier + redirect_uri to your backend.
  • Keep QF_CLIENT_SECRET on the backend and perform /oauth2/token exchange and refresh there.
  • Have your backend or serverless proxy call User APIs with x-auth-token and x-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.

Public-client exception

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.

StatusWhat it usually meansWhat to do
400 or 422Invalid request, missing required parameters, or validation failureFix the request or form data before retrying.
401Missing, expired, or invalid user access_tokenIf you have a refresh_token, refresh once and retry once. If it still fails, require the user to sign in again.
403Missing scope/permission, wrong environment, or a browser/origin restrictionRoute web calls through your backend, confirm the token environment, and request the correct scopes.
429Rate limit exceededBack off and retry later. Prefer exponential backoff with jitter.
500, 502, 503, 504Temporary server or upstream failureRetry 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​

PlatformRecommended patternStart here
WebFrontend or mobile app: in-app public exchange. Backend/server app: server-side session and exchange.Web integration example
React NativeFrontend or mobile app: in-app public exchange. Backend/server app: backend exchange.React Native guide
AndroidFrontend or mobile app: AppAuth public exchange. Backend/server app: backend exchange.Android guide
iOSFrontend or mobile app: AppAuth public exchange. Backend/server app: backend exchange.iOS guide
Full OAuth2 and OIDC detailsStep-by-step flow, validation, refresh, scopes, and troubleshootingOAuth2 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:

Next Steps​

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].