Authentication overview

Uploadcare's authentication system is designed to secure access to its file management, processing, and delivery services. It primarily relies on API keys, which are categorized into public and secret keys, each serving distinct purposes based on the operation's sensitivity and the client's environment. Public keys are generally used for client-side operations that do not require elevated permissions, such as initiating file uploads from a web browser. Secret keys, conversely, are reserved for server-side operations that involve managing files, applying transformations, or accessing sensitive project settings. The strategic use of these keys helps maintain a separation of concerns, ensuring that client-side applications have minimal necessary permissions while server-side components can perform more privileged actions securely. For operations requiring an additional layer of security, such as direct uploads from untrusted environments or restricting access to specific files, Uploadcare implements signed uploads, which involve generating a cryptographic signature to validate requests.

The authentication process ensures that only authorized applications and users can interact with Uploadcare's infrastructure, protecting against unauthorized access and data manipulation. This system integrates with various programming languages and frameworks through dedicated SDKs, simplifying the implementation of secure file workflows. Understanding the distinction between public and secret keys, and when to employ signed uploads, is fundamental to building secure and efficient applications with Uploadcare, as detailed in the official Uploadcare API reference.

Supported authentication methods

Uploadcare supports a few primary authentication methods to secure interactions with its API, tailored for different use cases and security requirements. These methods are designed to provide flexibility while maintaining a strong security posture for file management and delivery.

  1. Public API Keys: These keys are used for client-side operations, primarily for initializing the file uploader widget and performing basic file uploads. They are designed to be exposed in frontend code and do not grant access to sensitive project settings or file management operations. Public keys identify your project and enable the Uploadcare widget to function correctly.
  2. Secret API Keys: Secret keys are for server-side operations that require privileged access, such as managing uploaded files, deleting files, applying advanced transformations, and interacting with the REST API. These keys must be kept confidential and should never be exposed in client-side code. They provide full control over your project's files and settings.
  3. Signed Uploads: For scenarios where uploads are initiated directly from a client without a trusted backend, or when specific restrictions need to be applied to uploaded files (e.g., file size limits, accepted file types, or direct storage), signed uploads offer an enhanced security mechanism. This method involves generating a cryptographic signature on your server using your secret key and including it with the upload request. The signature proves the authenticity and integrity of the upload request and can enforce specific policies, as described in Uploadcare's signed uploads documentation.

The choice of authentication method depends on the specific operation and the environment from which the request originates. Public keys are suitable for public-facing client applications, while secret keys are essential for backend services. Signed uploads bridge the gap, allowing secure client-side uploads with server-side policy enforcement.

Here's a breakdown of Uploadcare's authentication methods:

Method When to Use Security Level
Public API Key Client-side uploads, widget initialization, non-sensitive operations Low (for client-side exposure)
Secret API Key Server-side file management, API calls requiring full project control High (must be kept confidential)
Signed Uploads Client-side uploads requiring server-enforced policies or direct-to-S3 uploads High (combines client convenience with server control)

Getting your credentials

To begin using Uploadcare, you need to obtain your API keys from the Uploadcare Dashboard. These keys are fundamental for authenticating your requests and integrating Uploadcare services into your applications. The process involves creating a project, which then automatically generates the necessary credentials.

  1. Sign Up or Log In: Navigate to the Uploadcare website and either sign up for a new account or log in to an existing one.
  2. Create a Project: Once logged in, you will be prompted to create a new project if you don't have one already. Each project has its own set of API keys, allowing for isolated development and deployment environments.
  3. Access Project Settings: After creating a project, go to the project settings. Here, you will find your project's Public Key and Secret Key.
  4. Locate API Keys: The Public Key is typically displayed prominently and is used for client-side integrations. The Secret Key is often hidden for security reasons and requires an explicit action (like clicking a 'reveal' button) to view. It is crucial to copy these keys accurately.

It is important to understand that public keys are designed for client-side use and are not considered sensitive in the same way as secret keys. Secret keys, however, grant extensive control over your Uploadcare project and must be protected as carefully as any other sensitive credential. Compromise of a secret key could lead to unauthorized access to your uploaded files and project settings. The Uploadcare REST API documentation provides further guidance on using these credentials effectively.

Authenticated request example

Authenticating requests with Uploadcare typically involves including your API keys in the request. For client-side uploads using the Uploadcare widget, the public key is usually passed during initialization. For server-side operations, the secret key is used to sign requests or as an authorization header. Below is an example of a server-side Python request to list files, demonstrating the use of a secret API key for authentication.

This example uses the requests library in Python to make a GET request to the Uploadcare REST API to retrieve a list of files. The secret key and public key are included in the Authorization header and as a query parameter, respectively.


import requests

PUBLIC_KEY = 'YOUR_PUBLIC_KEY'
SECRET_KEY = 'YOUR_SECRET_KEY'

# Base URL for the Uploadcare REST API
API_BASE_URL = 'https://api.uploadcare.com/files/'

headers = {
    'Authorization': f'Uploadcare.Simple {PUBLIC_KEY}:{SECRET_KEY}',
    'Accept': 'application/vnd.uploadcare-v0.7+json'
}

params = {
    'limit': 5,
    'ordering': '-datetime_uploaded'
}

try:
    response = requests.get(API_BASE_URL, headers=headers, params=params)
    response.raise_for_status()  # Raise an HTTPError for bad responses (4xx or 5xx)
    files_data = response.json()

    print("Successfully fetched files:")
    for file_info in files_data['results']:
        print(f"  UUID: {file_info['uuid']}, Filename: {file_info['original_filename']}")

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err}")
    print(f"Response content: {response.text}")
except requests.exceptions.ConnectionError as conn_err:
    print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
    print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
    print(f"An unexpected error occurred: {req_err}")

In this Python example, YOUR_PUBLIC_KEY and YOUR_SECRET_KEY must be replaced with your actual Uploadcare API keys. The Authorization header uses the Uploadcare.Simple scheme, combining both keys separated by a colon. This method is suitable for server-to-server communication where the secret key can be securely stored and managed. For more complex scenarios or different programming languages, refer to the Uploadcare REST API documentation and the specific Uploadcare SDK documentation for your chosen language.

Security best practices

Implementing robust security practices for authentication is critical when working with any API, especially one handling file uploads and content management. For Uploadcare, adhering to these best practices helps protect your data and prevent unauthorized access.

  • Keep Secret Keys Confidential: Your Uploadcare Secret Key grants full control over your project. Never expose it in client-side code (e.g., JavaScript in a browser), mobile applications, or public repositories. Store it in environment variables on your server, a secure configuration management system, or a secrets manager. This aligns with general security principles for API keys, as outlined by resources like Google Cloud's API key best practices.
  • Use Environment Variables for Keys: When deploying your application, store API keys as environment variables rather than hardcoding them directly into your source code. This practice prevents keys from being committed to version control systems and makes it easier to manage different keys for development, staging, and production environments.
  • Implement Signed Uploads for Client-Side Control: If you allow direct file uploads from a client (e.g., a browser or mobile app) without routing through your server, use Uploadcare's signed uploads feature. This allows your server to generate a secure signature that includes specific upload policies (e.g., file size limits, accepted MIME types, storage options). The client then uses this signature to authorize the upload, ensuring that only valid and policy-compliant files are accepted, preventing malicious uploads or policy circumvention. Consult the Uploadcare documentation on signed uploads for implementation details.
  • Restrict Permissions: While Uploadcare's API key system doesn't offer granular scope-based permissions beyond public/secret, ensure that any system or service using a secret key only has access to the specific resources and operations it needs. Regularly review access patterns.
  • Rotate Keys Regularly: Periodically rotate your API keys, especially secret keys. This practice minimizes the risk associated with a compromised key, as the old key will eventually become invalid. If you suspect a key has been compromised, revoke it immediately through the Uploadcare Dashboard and generate a new one.
  • Monitor API Usage: Keep an eye on your Uploadcare project's usage metrics and logs. Unusual activity, such as a sudden spike in file deletions or uploads from unexpected locations, could indicate a security breach.
  • Secure Your Backend: Ensure the server-side components that handle your secret keys and generate signed upload tokens are themselves secure. This includes regular security updates, strong access controls, and network security measures to protect against common web vulnerabilities.
  • Utilize HTTPS: Always interact with the Uploadcare API over HTTPS to encrypt data in transit, protecting your API keys and file content from eavesdropping. Uploadcare's API endpoints are designed to enforce HTTPS.

By integrating these security best practices into your development and deployment workflows, you can significantly enhance the security posture of your Uploadcare integration and protect your digital assets.