Authentication overview

Quran Cloud's API utilizes a straightforward authentication model centered on API keys. This approach allows developers to programmatically access Quranic data, including text, translations, and audio files, while ensuring that requests originate from authorized sources. API keys serve as unique identifiers and access tokens, linking API calls to a specific user account and its associated plan limits. Each request made to the Quran Cloud API must include a valid API key for successful processing, enabling the service to manage usage and enforce subscription tiers.

The API key model is a common practice for many commercial APIs due to its simplicity and ease of implementation for both developers and API providers API key authentication overview. For Quran Cloud, this means that once registered, users are issued a key that they embed into their application's requests. The system then validates this key against its records before serving the requested data, ensuring data integrity and preventing unauthorized access to the Quran Cloud API endpoints Quran Cloud API documentation.

Supported authentication methods

Quran Cloud supports a single primary authentication method: API Key authentication. This method involves transmitting a unique key with each API request.

The following table outlines the details of this supported authentication method:

Method When to Use Security Level Notes
API Key All API interactions with Quran Cloud. Suitable for server-side applications, client-side applications (with careful key management), and scripts. Moderate The key identifies the user and their subscription plan. Must be kept confidential to prevent unauthorized usage and potential billing implications. Transmitted via HTTP headers or query parameters.

Getting your credentials

Accessing the Quran Cloud API requires a valid API key. This key is provisioned to you upon registration and subscription to a Quran Cloud plan, including the free Developer Plan. Follow these steps to obtain and manage your API key:

  1. Register for an Account: Navigate to the Quran Cloud homepage and sign up for a new account. You can choose the Developer Plan to start with 10,000 free requests per month.

  2. Access Your Dashboard: After successful registration and login, you will be redirected to your personal dashboard. This is the central hub for managing your account, subscriptions, and API keys.

  3. Locate Your API Key: Within the dashboard, there will be a dedicated section, typically labeled 'API Key' or 'Developer Settings', where your unique API key is displayed. This key is a string of alphanumeric characters.

  4. Copy Your API Key: Carefully copy the displayed API key. It is crucial to treat this key as a sensitive credential, similar to a password.

  5. Regenerate Key (Optional): If you suspect your API key has been compromised, or as part of a regular security practice, you can regenerate your key from the dashboard. Regenerating a key invalidates the previous one, requiring you to update all applications using the old key.

For detailed visual guides and the most current instructions, always refer to the official Quran Cloud API documentation.

Authenticated request example

Once you have obtained your API key, you will include it in the headers or query parameters of your HTTP requests to the Quran Cloud API. The documentation specifies that the API key should be passed as a query parameter named api_key.

Here's an example of how to make an authenticated request to retrieve data using cURL, Python, and JavaScript:

cURL Example

curl -X GET \
  'https://api.qurancloud.com/v1/ayah/1:1?api_key=YOUR_API_KEY_HERE' \
  -H 'Content-Type: application/json'

In this cURL command:

  • -X GET specifies the HTTP GET method.
  • 'https://api.qurancloud.com/v1/ayah/1:1?api_key=YOUR_API_KEY_HERE' is the API endpoint, with YOUR_API_KEY_HERE replaced by your actual API key. This example fetches the first ayah of the first surah.
  • -H 'Content-Type: application/json' sets the content type of the request.

Python Example

import requests

api_key = "YOUR_API_KEY_HERE"
base_url = "https://api.qurancloud.com/v1"
endpoint = f"{base_url}/ayah/1:1"

params = {
    "api_key": api_key
}

headers = {
    "Content-Type": "application/json"
}

response = requests.get(endpoint, params=params, headers=headers)

if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code} - {response.text}")

This Python script uses the requests library to perform a GET request:

  • The api_key variable holds your actual key.
  • The params dictionary is used to pass the API key as a query parameter.
  • The headers dictionary sets the Content-Type.
  • The response is parsed as JSON if successful.

JavaScript (Fetch API) Example

const apiKey = "YOUR_API_KEY_HERE";
const baseUrl = "https://api.qurancloud.com/v1";
const endpoint = `${baseUrl}/ayah/1:1?api_key=${apiKey}`;

fetch(endpoint, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
})
.then(response => {
    if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();
})
.then(data => {
    console.log(data);
})
.catch(error => {
    console.error('Error fetching data:', error);
});

This JavaScript example uses the browser's native Fetch API:

  • The apiKey is directly embedded into the endpoint URL as a query parameter.
  • The method is set to GET, and headers include Content-Type.
  • Error handling is included to catch network or API response issues.

Security best practices

Securing your API key and the applications that use the Quran Cloud API is critical to prevent unauthorized access, potential misuse, and to maintain the integrity of your service. Adhere to these best practices:

  • Keep API Keys Confidential: Treat your API key as a sensitive password. Never embed it directly into client-side code (e.g., public JavaScript files) if it's not strictly necessary, as it can be easily extracted. If client-side usage is unavoidable, consider using a proxy server to append the key or implement rate limiting and domain restrictions on the key itself if the API provider supports it Google Maps API key best practices.

  • Use Environment Variables: For server-side applications, store your API key in environment variables rather than hardcoding it directly into your source code. This prevents the key from being exposed in version control systems or publicly accessible codebases.

  • Implement Server-Side Calls: Whenever possible, make API calls from your backend server rather than directly from client-side applications. This strategy keeps your API key secure on your server and only exposes the necessary data to the client.

  • Secure Communication (HTTPS): Always use HTTPS for all API requests to Quran Cloud. This ensures that the API key and all data transmitted between your application and the API are encrypted, protecting against eavesdropping and man-in-the-middle attacks. Quran Cloud enforces HTTPS for its API endpoints.

  • Regular Key Rotation: Periodically regenerate your API key from the Quran Cloud dashboard. This minimizes the risk associated with a compromised key, as an old, exposed key will no longer grant access after rotation.

  • Monitor Usage: Regularly check your API usage statistics in the Quran Cloud dashboard. Unusual spikes in usage might indicate unauthorized access or a compromised key, allowing you to take immediate action.

  • Error Handling: Implement robust error handling in your applications. Specifically, handle authentication errors gracefully (e.g., HTTP 401 Unauthorized responses) to avoid exposing sensitive information or creating security vulnerabilities in your application's logic.

  • Restrict Access (If Available): If Quran Cloud offers features to restrict API key usage by IP address or referer (domain), enable these restrictions. This adds an extra layer of security, ensuring that even if your key is exposed, it can only be used from authorized locations or domains.