Authentication overview

Beeceptor enables developers to create mock APIs, inspect HTTP requests, and test webhooks. To ensure secure interaction with your Beeceptor account and its programmatic features, authentication is required when using the Beeceptor Management API. This API allows for the automation of tasks such as creating and managing mock endpoints, retrieving request history, and modifying rules without direct interaction with the Beeceptor web interface.

The primary method for authenticating with Beeceptor's management API is through the use of API keys. These keys act as unique identifiers and secret tokens, granting access to your account's resources. When an API key is used, it is typically included in the request headers, allowing the Beeceptor service to verify the sender's identity and authorize the requested operation. This approach is common in API-driven development, providing a balance between security and ease of integration for server-to-server communication or automated scripts.

For direct interaction with your mock endpoints, Beeceptor itself does not impose authentication by default. This design facilitates easy testing and integration without requiring credentials for every request to a mock. However, developers can configure custom rules on their Beeceptor endpoints to simulate authentication mechanisms, such as requiring specific headers or tokens, to test how their client applications handle various authentication flows. This distinction is crucial: authentication protects access to your Beeceptor account and its configuration, while mock endpoint security is configurable by the user to simulate real-world API behaviors.

Supported authentication methods

Beeceptor's programmatic access primarily relies on a single, consistent authentication method for its management API:

API Key Authentication

API key authentication involves a unique string that is generated within your Beeceptor account and then included in API requests. This key serves as both an identifier and a secret, allowing Beeceptor to verify the origin and authorization of the request. It is a straightforward method widely adopted for server-to-server communication and scripting where user interaction is not involved. API keys are typically passed in the Authorization header using a Bearer token scheme, or as a custom header, depending on the specific API endpoint's requirements. For Beeceptor's management API, the key is generally expected as a Bearer token.

When to use Beeceptor API Keys:

  • Automating the creation, modification, or deletion of Beeceptor mock endpoints.
  • Retrieving historical request data from your Beeceptor proxies programmatically.
  • Integrating Beeceptor management tasks into CI/CD pipelines or automated testing frameworks.
  • Scripting interactions with your Beeceptor account from local development environments.

While other authentication methods like OAuth 2.0 or mutual TLS are used in more complex enterprise environments, API keys are sufficient for Beeceptor's scope, which focuses on developer tooling and mocking services. For instance, OAuth 2.0 is designed for delegated authorization, allowing third-party applications to access user resources without sharing credentials, as seen in many modern web service integrations.

Beeceptor Authentication Methods Overview
Method When to Use Security Level Notes
API Key Programmatic access to Beeceptor Management API; automation of mock setup and data retrieval. Moderate Requires secure handling of the key; typically passed as a Bearer token in the Authorization header.

Getting your credentials

To obtain an API key for authenticating with the Beeceptor Management API, you need to access your Beeceptor account settings through the web interface. This process involves generating a new key, which will then be displayed to you for immediate use.

  1. Log in to Beeceptor: Navigate to the Beeceptor website and log in to your account.
  2. Access Account Settings: Once logged in, locate and click on your profile or account icon, usually found in the top right corner of the dashboard. Select "Account Settings" or a similar option from the dropdown menu.
  3. Navigate to API Keys Section: Within the account settings, look for a section specifically dedicated to "API Keys" or "Integrations."
  4. Generate New API Key: Click on the button to "Generate New API Key" or "Create Key." You may be prompted to provide a name or description for the key to help you manage multiple keys later.
  5. Copy the API Key: After generation, the new API key will be displayed. It is crucial to copy this key immediately and store it securely, as it may not be retrievable again for security reasons. If lost, you will need to generate a new key and revoke the old one.

Each API key is unique to your account and grants access commensurate with your account's permissions. It is recommended to generate separate keys for different applications or environments to facilitate easier revocation and management if a key is compromised or no longer needed. For detailed instructions, refer to the official Beeceptor documentation on API key management.

Authenticated request example

Once you have obtained your Beeceptor API key, you can use it to make authenticated requests to the Beeceptor Management API. The most common way to include the API key is as a Bearer token in the Authorization header of your HTTP requests. Below is an example using cURL to create a new mock endpoint.

In this example, YOUR_API_KEY should be replaced with the actual API key you generated from your Beeceptor account. The request body (-d parameter) specifies the configuration for the new mock endpoint, including its name and a default response.


curl -X POST \ 
  https://api.beeceptor.com/v1/endpoints \ 
  -H "Content-Type: application/json" \ 
  -H "Authorization: Bearer YOUR_API_KEY" \ 
  -d '{ 
      "name": "my-new-mock-endpoint", 
      "rules": [ 
          { 
              "request": { "method": "GET", "path": "/hello" }, 
              "response": { "statusCode": 200, "body": "Hello from Beeceptor!" } 
          } 
      ] 
  }'

This cURL command sends a POST request to the /v1/endpoints path of the Beeceptor API. The Authorization: Bearer YOUR_API_KEY header ensures that the request is authenticated. The JSON payload defines a new endpoint named my-new-mock-endpoint that responds with "Hello from Beeceptor!" when a GET request is made to /hello on that mock.

For other programming languages or tools, the principle remains the same: include the API key in the Authorization header with the Bearer prefix. For instance, in Python using the requests library, it would look like this:


import requests

api_key = "YOUR_API_KEY"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}

payload = {
    "name": "python-created-mock",
    "rules": [
        {
            "request": { "method": "GET", "path": "/data" },
            "response": { "statusCode": 200, "body": {"message": "Data from Python"}} 
        }
    ]
}

response = requests.post("https://api.beeceptor.com/v1/endpoints", headers=headers, json=payload)
print(response.json())

This Python example demonstrates constructing the same request programmatically, emphasizing the consistent pattern for API key usage across different client environments. This adherence to standard HTTP authentication practices makes Beeceptor's API accessible to a wide range of development tools and languages.

Security best practices

Securing your Beeceptor API keys and authenticated access is critical to prevent unauthorized management of your mock endpoints and access to sensitive request data. Adhere to the following best practices:

  • Treat API Keys as Sensitive Credentials: Your Beeceptor API key grants full access to manage your mocks. Treat it with the same level of security as you would a password or private key. Avoid hardcoding API keys directly into your application's source code, especially in client-side applications or publicly accessible repositories.
  • Use Environment Variables: For server-side applications, scripts, and CI/CD pipelines, store API keys in environment variables. This keeps them out of your codebase and allows for easy rotation without code changes. For example, in a Linux/Unix environment, you might set export BEECEPTOR_API_KEY="YOUR_API_KEY".
  • Secure Configuration Management: If environment variables are not feasible, use secure configuration management systems (e.g., HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, Google Secret Manager) to store and retrieve API keys at runtime. These services are designed to protect sensitive data.
  • Restrict Access to API Keys: Limit who has access to your API keys. Only individuals or systems that absolutely require programmatic access to Beeceptor should have knowledge of or access to these keys.
  • Regularly Rotate API Keys: Periodically generate new API keys and revoke old ones. This practice reduces the window of opportunity for a compromised key to be exploited. Beeceptor allows you to manage and revoke keys from your account settings.
  • Implement Least Privilege: While Beeceptor API keys generally grant broad access, if Beeceptor introduces more granular permissions in the future, configure keys with the minimum necessary permissions required for their intended function.
  • Monitor API Key Usage: Keep an eye on your API access logs, if available, to detect any unusual activity or unauthorized usage patterns. High volumes of requests from unexpected locations could indicate a compromised key.
  • Use HTTPS: Always ensure that all communication with the Beeceptor Management API occurs over HTTPS. This encrypts the data in transit, protecting your API key from interception by malicious actors. All official Beeceptor API endpoints are served over HTTPS by default. This is a fundamental principle for securing web communications, as detailed in Mozilla's explanation of HTTPS.
  • Revoke Compromised Keys Immediately: If you suspect an API key has been compromised, revoke it immediately through your Beeceptor account settings and generate a new one.

By following these security best practices, you can significantly reduce the risk associated with using API keys and maintain the integrity of your Beeceptor account and mock environments.