Secure access

Jan Cerman
4 minutes
Delivery API
Protect your content and assets with secure access. You might want to enable secure access with sensitive content, content hidden behind sign-in walls, or for projects that are not public facing.Without secure access, your assets and published content items are publicly available by default.

Enable secure access

When you activate secure access, Delivery API requires an API key with each API request for content. This applies to both Delivery REST API and Delivery GraphQL API.
  1. In Kontent.ai, go to  Environment settings > General.
  2. In Enabled APIs, use the toggle to activate Secure access for Delivery API.
  3. In Project settings > API keys, create a Delivery API key with permission for secure access.
Use the new API key to authenticate your API requests.
An image showing two enabled APIs, where one of them is the Delivery API's secure access activated for an environment.

Retrieve content items securely

Tips for staying safe with secure access
  • Retrieve content on the server side and NOT on the client side to prevent leaking your API keys.
  • Store your API Keys outside your source code. For example, store them as environment variables. Make sure they’re encrypted too.
  • Rotate your API keys periodically. The older an API key is, the higher the probability it could have been compromised.
  • Before you regenerate or revoke an API key, ensure your apps use a new API key to prevent downtime.
When getting content items, specify the API key when making requests. The code below shows how to securely retrieve the content of an article named My article.
  • PHP
<?php
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Defined by Composer to include required libraries
require __DIR__ . '/vendor/autoload.php';

use Kontent\Ai\Delivery\DeliveryClient;

$client = new DeliveryClient('KONTENT_AI_ENVIRONMENT_ID', null, 'KONTENT_AI_DELIVERY_API_KEY');

$item = $client->getItem('my_article');
?>
After sending the request, you receive a single content item in the JSON format. You can filter your requests to retrieve only specific elements or items.

Retrieve assets securely

Do you manage confidential assets or need to run an intranet website? In that case, you might want to keep your assets away from the public. You can restrict access to your assets by requiring an API key. This API key differs from the API keys in Project settings > API keys. To set up secure access for assets, contact our support and let them know the following: Once you enable secure assets, you need to provide an API key for every asset request. Fetch assets on the server side of your app to prevent exposing the API key.
This feature isn’t available for some legacy plan subscriptions. Contact us to find out your options.

Revoke API keys

When you suspect unauthorized key usage, you need to switch to a new API key and revoke the old one. For example, when a user leaves your company. We recommend switching to a newly created API key and revoking the old API key. The revocation process can take up to a couple of minutes. Any requests made with a revoked API key receive the 401 Unauthorized error.