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.
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.
In Kontent.ai, go to Environment settings > General.
In Enabled APIs, use the toggle to activate Secure access for Delivery API.
Use the new API key to authenticate your API requests.
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.
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.
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.
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.
This feature isn’t available for some legacy plan subscriptions. Contact us to find out your options.
C#
// Tip: Find more about .NET SDKs at https://kontent.ai/learn/netusing Kontent.Ai.Delivery;// Tip: Use DI to create Delivery client https://kontent.ai/learn/net-register-clientIDeliveryClient client = DeliveryClientBuilder .WithOptions(builder => builder .WithEnvironmentId("KONTENT_AI_ENVIRONMENT_ID") .UseProductionApi("KONTENT_AI_DELIVERY_API_KEY") .Build()) .Build();// Gets a specific content item// Tip: Create strongly typed models according to https://kontent.ai/learn/net-strong-typesIDeliveryItemResponse<Article> response = await client.GetItemAsync<Article>("my_article");Article item = response.Item;
Secure access | Kontent.ai Learn
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.