Authentication overview

The Dropbox API uses OAuth 2.0 for authentication, which allows applications to obtain limited access to a user's Dropbox account without exposing the user's login credentials. This delegated authorization framework is a standard for web and mobile applications, ensuring both security and user control over their data permissions. Applications request specific permissions (scopes), and users grant or deny these requests through a Dropbox-hosted authorization page.

Once authorized, the application receives an access token, which is a credential that grants access to the Dropbox API on behalf of the user. This token must be included in the Authorization header of all API requests. Dropbox API supports both HTTP and RPC (Remote Procedure Call) styles for its endpoints, with authentication handled consistently across both approaches via the access token.

Supported authentication methods

Dropbox API primarily supports OAuth 2.0, offering several grant types to accommodate different application architectures and security requirements. Understanding the appropriate flow for your application is crucial for secure and efficient integration.

Method When to Use Security Level
OAuth 2.0 Authorization Code Grant Web applications (server-side), mobile/desktop apps with PKCE. Requires a confidential client (server-side). High (client secret exchanged server-side, short-lived authorization code)
OAuth 2.0 Implicit Grant Single-page applications (SPAs) or client-side web apps where a client secret cannot be securely stored. Access token returned directly in URL fragment. Moderate (token exposed in URL, no refresh token typically)
OAuth 2.0 PKCE (Proof Key for Code Exchange) Public clients like mobile and desktop applications. Prevents authorization code interception attacks. Used with Authorization Code Grant. High (mitigates code interception, no client secret required for public clients)
Refresh Tokens To obtain new access tokens without re-prompting the user for authorization. Issued alongside the initial access token in Authorization Code Grant. High (long-lived but securely stored, used to minimize user interaction)

The choice of OAuth 2.0 flow depends on the client type and its ability to securely store credentials. For server-side applications, the Authorization Code Grant is recommended. Public clients like mobile or desktop applications should utilize the Authorization Code Grant with PKCE for enhanced security, as described in the OAuth 2.0 Proof Key for Code Exchange (PKCE) specification.

Getting your credentials

To begin integrating with the Dropbox API, you must register your application in the Dropbox App Console. This process provides the necessary credentials for OAuth 2.0 authentication.

  1. Create a Dropbox Developer Account: If you don't have one, sign up at the Dropbox Developers documentation portal.

  2. Create a New App: Navigate to the Dropbox App Console and click "Create app".

  3. Choose an API and Access Type:

    • Select "Scoped access" for fine-grained permissions or "Full Dropbox" for broader access (less common for new apps).
    • Choose the type of app (e.g., "API and File access").
  4. Configure App Details:

    • App Name: Provide a unique name for your application.
    • Redirect URIs: Specify the URI(s) where Dropbox will redirect users after authorization. These must exactly match the URIs used in your OAuth flow. For development, http://localhost:8000/ or similar is common.
    • Permissions: Select the specific API permissions (scopes) your app requires (e.g., files.content.read, files.content.write). Only request permissions essential for your app's functionality to adhere to the principle of least privilege.
  5. Retrieve Credentials: After creating the app, you will be provided with:

    • App key: Your client ID (public identifier for your application).
    • App secret: Your client secret (a confidential key used by server-side applications for secure token exchange). Keep this secret secure and never expose it in client-side code.
  6. Generate Access Tokens (for development/testing): For initial testing or simple scripts, you can manually generate a short-lived access token from the App Console under the "OAuth 2" section. For production, applications must implement the full OAuth 2.0 flow.

Authenticated request example

Once you have obtained an access token (e.g., YOUR_ACCESS_TOKEN) through one of the OAuth 2.0 flows, you can use it to make authenticated requests to the Dropbox API. The access token is typically sent in the Authorization header using the Bearer scheme.

Here's an example using curl to list the contents of a folder:

curl -X POST https://api.dropboxapi.com/2/files/list_folder \ 
    --header "Authorization: Bearer YOUR_ACCESS_TOKEN" \ 
    --header "Content-Type: application/json" \ 
    --data "{\"path\": \"\", \"recursive\": false, \"include_media_info\": false, \"include_deleted\": false, \"include_has_explicit_shared_members\": false, \"include_mounted_folders\": true, \"include_non_downloadable_files\": false}"

Many official Dropbox SDKs abstract this process, handling the token management and request formulation. For instance, using the Python SDK:

import dropbox

db = dropbox.Dropbox("YOUR_ACCESS_TOKEN")

try:
    # List contents of the root folder
    for entry in db.files_list_folder("").entries:
        print(entry.name)
except dropbox.exceptions.ApiError as err:
    print(f'*** API error: {err}')
except Exception as err:
    print(f'*** Other error: {err}')

For more detailed examples and SDK-specific guidance, refer to the Dropbox API reference documentation.

Security best practices

Adhering to security best practices is essential when implementing Dropbox API authentication to protect user data and maintain application integrity.

  • Use HTTPS Everywhere: All communication with the Dropbox API, including authorization redirects and token exchanges, must occur over HTTPS to prevent man-in-the-middle attacks and protect sensitive data in transit. This is a fundamental principle for secure API interactions, as emphasized by the OAuth 2.0 RFC 6749 specification.

  • Securely Store Client Secrets: If your application uses an App secret (client secret), ensure it is stored securely on your server and never exposed in client-side code, mobile apps, or public repositories. Compromised client secrets can lead to unauthorized access.

  • Implement PKCE for Public Clients: For mobile and desktop applications (public clients), always use the Authorization Code Grant with PKCE. This prevents authorization code injection attacks where a malicious application could intercept the authorization code and exchange it for an access token.

  • Validate Redirect URIs: Carefully configure and validate your Redirect URIs in the Dropbox App Console. Only allow trusted URIs to prevent malicious redirects and token leakage. Always use specific, fully qualified URIs rather than broad wildcards.

  • Request Minimal Scopes: Follow the principle of least privilege by requesting only the API permissions (scopes) that your application absolutely needs to function. This limits the potential impact if your access token is compromised.

  • Protect Access Tokens: Access tokens grant direct access to user data. Treat them as sensitive credentials:

    • Never hardcode them.
    • Store them securely (e.g., encrypted on a server, in secure storage for mobile apps).
    • Transmit them only via HTTPS.
    • Avoid logging them in plain text.
  • Handle Refresh Tokens Securely: If your application uses refresh tokens to obtain new access tokens, ensure they are stored with the highest level of security, typically on a server-side storage solution. Refresh tokens are long-lived and, if compromised, could grant persistent access to a user's account.

  • Implement Token Revocation: Provide users with a mechanism to revoke your application's access from their Dropbox account settings. Also, be prepared to revoke tokens programmatically if a security incident occurs.

  • Error Handling and Logging: Implement robust error handling for authentication failures and log relevant (non-sensitive) information for debugging. Monitor for unusual authentication patterns that might indicate an attack.

  • Keep SDKs and Libraries Updated: Regularly update Dropbox SDKs and any third-party OAuth libraries to benefit from the latest security patches and best practices.