Authentication overview
Contentstack's authentication architecture is designed to secure access to its content management system (CMS) and associated APIs. The system differentiates between user authentication for the Contentstack web interface and API authentication for programmatic interactions. For users accessing the Contentstack graphical user interface, standard email and password authentication is supported, alongside Single Sign-On (SSO) options for enterprise environments. This ensures that only authorized personnel can log in and manage content within the platform.
For API interactions, Contentstack primarily relies on token-based authentication. This approach involves generating unique tokens that are then included in API requests to verify the identity and permissions of the requesting application or service. This method provides granular control over what content can be accessed or modified, depending on the type and scope of the token used. The use of tokens aligns with common API security practices, offering a stateless authentication mechanism that is scalable and efficient for headless CMS operations. Further details on Contentstack's security protocols are available in their official documentation on Contentstack security and compliance.
The token-based system is critical for developers integrating Contentstack with various front-end applications, mobile apps, or other third-party services. By using different token types for content delivery versus content management, Contentstack enables developers to implement the principle of least privilege, granting only the necessary permissions for each specific use case. This separation helps in mitigating potential security risks by limiting the scope of access even if a token is compromised. Contentstack's approach to API authentication is consistent with industry standards for securing web APIs, as outlined by organizations such as the OAuth 2.0 framework.
Supported authentication methods
Contentstack supports several authentication methods tailored for different use cases, primarily distinguishing between API access and user interface access. The core of its API authentication revolves around token-based mechanisms.
API Authentication Tokens
Contentstack utilizes two primary types of tokens for API authentication:
- Management Tokens: These tokens are used for programmatic content management operations, such as creating, updating, deleting, and publishing content. They grant access to the Content Management API (CMA), which allows developers to automate workflows and integrate Contentstack with other systems. Management Tokens typically have broader permissions and should be handled with a high degree of security. For detailed information on their scope, refer to the Contentstack Management Token documentation.
- Delivery Tokens: Designed for content retrieval, Delivery Tokens are used with the Content Delivery API (CDA) or GraphQL API. They allow read-only access to published content, making them suitable for front-end applications, mobile apps, and static site generators. Delivery Tokens are generally less sensitive than Management Tokens as they do not permit content modification or deletion. More information on their usage can be found in the Contentstack Delivery Token guide.
User Interface Authentication
For direct access to the Contentstack web interface by content editors, developers, and administrators, the following methods are supported:
- Email and Password: Standard user authentication where users log in with their registered email address and a password. This is the default method for individual users and smaller teams.
- Single Sign-On (SSO): For enterprise clients, Contentstack integrates with various SSO providers, allowing users to authenticate using their existing corporate credentials. This enhances security and simplifies user management by centralizing identity verification. Contentstack supports SSO via SAML 2.0 and OAuth 2.0, which are widely adopted protocols for enterprise identity management. Further details on setting up SSO are available in the Contentstack SSO configuration documentation.
Authentication Method Summary
| Method | When to Use | Security Level / Scope |
|---|---|---|
| Management Token | Programmatic content creation, updates, deletion (CMA) | High (write/read access to content) |
| Delivery Token | Retrieving published content (CDA, GraphQL API) | Medium (read-only access to published content) |
| Email & Password | Direct user login to Contentstack UI | Standard user authentication |
| Single Sign-On (SSO) | Enterprise user login to Contentstack UI via identity provider | High (centralized identity management) |
Getting your credentials
To interact with Contentstack's APIs, you will need to generate specific credentials within the Contentstack web interface. The process differs slightly depending on whether you require a Management Token or a Delivery Token.
Generating Management Tokens
Management Tokens are created at the stack level and are used for API calls that modify content. To generate a Management Token:
- Log in to your Contentstack account.
- Navigate to the desired stack.
- In the left navigation panel, go to Settings > Tokens.
- Click on the Management Tokens tab.
- Click + New Management Token.
- Provide a descriptive name for the token and configure its permissions. You can specify read, write, and publish permissions for various content types and environments.
- Click Generate Token.
- Copy the generated token immediately, as it will not be displayed again for security reasons. Store it securely. Contentstack provides a detailed guide on creating Management Tokens.
Generating Delivery Tokens
Delivery Tokens are also created at the stack level and are used for retrieving published content. To generate a Delivery Token:
- Log in to your Contentstack account.
- Navigate to the desired stack.
- In the left navigation panel, go to Settings > Tokens.
- Click on the Delivery Tokens tab.
- Click + New Delivery Token.
- Provide a descriptive name for the token.
- Select the environments and languages for which this token will grant access to published content.
- Click Generate Token.
- Copy the generated token immediately and store it securely. For more specific instructions, refer to the Contentstack Delivery Token creation guide.
Other Credentials
- API Key: Each Contentstack stack has a unique API Key, which is required alongside Delivery Tokens for most Content Delivery API requests. This key identifies the specific stack you are interacting with. You can find your API Key in the Settings > Stack section of your Contentstack account.
- Environment Name: When making Content Delivery API requests, you also need to specify the environment (e.g., 'development', 'production') from which to retrieve content. This is configured when setting up your environments in Contentstack.
Authenticated request example
This example demonstrates how to make an authenticated request to Contentstack's Content Delivery API to retrieve content, using a Delivery Token, API Key, and Environment Name. The example uses curl for simplicity, but the principles apply across various programming languages and SDKs.
Content Delivery API Request (Retrieve Entries)
To retrieve entries from a specific content type:
curl -X GET \
'https://cdn.contentstack.io/v3/content_types/{content_type_uid}/entries?environment={environment_name}' \
-H 'api_key: {YOUR_STACK_API_KEY}' \
-H 'access_token: {YOUR_DELIVERY_TOKEN}'
Replace the placeholders:
{content_type_uid}: The unique ID of the content type you want to retrieve (e.g.,blog_post).{environment_name}: The name of the environment from which to fetch content (e.g.,developmentorproduction).{YOUR_STACK_API_KEY}: Your Contentstack stack's API Key.{YOUR_DELIVERY_TOKEN}: Your generated Delivery Token for the specified environment.
Content Management API Request (Create Entry)
To create a new entry using the Content Management API, you would use a Management Token. This example shows a POST request:
curl -X POST \
'https://api.contentstack.io/v3/content_types/{content_type_uid}/entries' \
-H 'api_key: {YOUR_STACK_API_KEY}' \
-H 'authtoken: {YOUR_MANAGEMENT_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{
"entry": {
"title": "My New Blog Post",
"body": "This is the content of my new blog post."
}
}'
Replace the placeholders:
{content_type_uid}: The unique ID of the content type where you want to create an entry.{YOUR_STACK_API_KEY}: Your Contentstack stack's API Key.{YOUR_MANAGEMENT_TOKEN}: Your generated Management Token. Note that for CMA, the header is typicallyauthtoken.
For more detailed API examples and parameters, consult the Contentstack API Reference documentation.
Security best practices
Securing your Contentstack integration involves careful management of tokens and adherence to general API security principles. Implementing these best practices helps protect your content and prevent unauthorized access.
Token Management
- Principle of Least Privilege: Always generate tokens with the minimum necessary permissions. For example, use Delivery Tokens for front-end applications that only need to read content, and restrict Management Tokens to automated processes that require write access. Avoid using Management Tokens in client-side code.
- Environment-Specific Tokens: Create separate Delivery Tokens for different environments (e.g., development, staging, production). This limits the blast radius if a token for a non-production environment is compromised.
- Regular Token Rotation: Periodically revoke old tokens and generate new ones. This practice reduces the window of opportunity for an attacker to exploit a compromised token.
- Secure Storage: Never hardcode tokens directly into your application's source code. Store them in secure environment variables, secret management services (e.g., AWS Secrets Manager, Azure Key Vault, Google Secret Manager), or a secure configuration file that is not committed to version control.
- Access Control: Limit who has access to generate and view tokens within the Contentstack UI. Utilize Contentstack's role-based access control (RBAC) to ensure only authorized team members can manage tokens.
API Security
- HTTPS Everywhere: All communication with Contentstack APIs should occur over HTTPS to ensure data encryption in transit. Contentstack APIs enforce HTTPS, but verify your application also uses secure connections.
- Input Validation: Implement robust input validation on any data sent to Contentstack via the Management API to prevent injection attacks and ensure data integrity.
- Error Handling: Implement secure error handling that avoids leaking sensitive information in error messages. Generic error messages are generally preferred in production environments.
- Rate Limiting: While Contentstack implements its own rate limiting, consider implementing client-side rate limiting or circuit breakers in your applications to prevent abuse and protect your services from excessive API calls.
- Monitoring and Logging: Monitor API access logs for unusual patterns or suspicious activity. Contentstack provides audit logs that can help track who accessed what and when. Integrate these logs with your centralized logging and monitoring solutions.
User and Application Security
- Strong Passwords and MFA: Encourage or enforce the use of strong, unique passwords and multi-factor authentication (MFA) for all Contentstack user accounts.
- Single Sign-On (SSO): For organizations, leverage Contentstack's SSO capabilities to centralize user authentication and benefit from your identity provider's security features.
- Secure Development Practices: Adhere to secure coding guidelines (e.g., OWASP Top 10) in your applications that interact with Contentstack APIs. Regularly review code for potential vulnerabilities.
- Dependency Security: Keep all libraries and frameworks used in your application up-to-date to patch known security vulnerabilities.
By consistently applying these security best practices, you can significantly enhance the security posture of your Contentstack implementation and protect your digital content assets. For further guidance, consult the Contentstack security documentation.