Authentication overview
Dailymotion's API employs OAuth 2.0 as its primary authorization framework. This industry-standard protocol enables third-party applications to obtain limited access to user accounts on an HTTP service, such as the Dailymotion platform, without exposing user credentials. Instead, applications acquire an access token that grants specific permissions (scopes) to access resources on behalf of the user or the application itself.
The OAuth 2.0 flow is designed to ensure that users maintain control over their data, deciding which applications can access their Dailymotion account and for what purposes. This approach is critical for applications that need to publish videos, manage channels, retrieve user-specific data, or perform other actions requiring user authorization. For applications that only need to access public data or perform actions on their own behalf (e.g., uploading videos to an owned channel without user interaction), a client credentials flow might be utilized where applicable.
Understanding OAuth 2.0 grant types is fundamental to implementing Dailymotion API authentication correctly. The choice of grant type depends on the nature of your application (web application, mobile app, server-side service) and the type of access required.
Supported authentication methods
Dailymotion's API primarily supports OAuth 2.0 with several grant types, accommodating various application architectures and use cases. The most common and recommended grant type for web applications is the Authorization Code flow.
OAuth 2.0 Authorization Code Grant
This is the recommended method for web server applications. It provides the highest level of security by exchanging an authorization code for an access token on the server-side, preventing tokens from being exposed in the client's browser. It is suitable for applications that need to access user-specific data or perform actions on behalf of a Dailymotion user.
- Flow: User grants permission → application receives authorization code → application exchanges code for access token (and refresh token) on its backend server.
- Use Cases: Web applications managing user uploads, personalized content feeds, or user channel interactions.
OAuth 2.0 Implicit Grant (Legacy)
While still supported, the Implicit Grant is generally discouraged for new applications due to security concerns, as access tokens are returned directly to the client (e.g., browser) via the URI fragment, making them vulnerable to interception. It was historically used for client-side applications where a server-side component was not feasible.
- Flow: User grants permission → application receives access token directly in URI fragment.
- Use Cases: Single-page applications (SPAs) or mobile apps, though Authorization Code with PKCE is now preferred for these.
OAuth 2.0 Client Credentials Grant
This grant type is suitable for applications that need to access their own service resources, rather than acting on behalf of a user. It's often used for machine-to-machine communication or when an application needs to manage its own content without user interaction.
- Flow: Application authenticates directly with its Client ID and Client Secret → receives an access token.
- Use Cases: Uploading videos to a dedicated Dailymotion channel owned by the application, managing application-specific settings, or accessing public API endpoints with higher rate limits.
Summary of Authentication Methods
| Method | When to Use | Security Level |
|---|---|---|
| OAuth 2.0 Authorization Code | Web applications requiring user authorization for persistent access. | High (tokens exchanged server-side) |
| OAuth 2.0 Implicit Grant | Legacy client-side applications (less secure, generally discouraged). | Medium-Low (token exposed in browser URI) |
| OAuth 2.0 Client Credentials | Server-to-server communication, managing application's own resources. | High (direct client authentication) |
Getting your credentials
To begin integrating with the Dailymotion API, you must first register your application and obtain Client ID and Client Secret credentials. These credentials uniquely identify your application to Dailymotion's authorization server and are essential for all OAuth 2.0 flows.
-
Create a Dailymotion Account: If you don't already have one, sign up for a Dailymotion account on their homepage.
-
Access the Developer Portal: Navigate to the Dailymotion Developer Portal. This portal is your central hub for managing API applications.
-
Register a New Application: Within the developer portal, locate the section for 'My Apps' or 'Register an Application'. You will typically be prompted to provide:
- Application Name: A user-friendly name for your application.
- Description: A brief explanation of your application's purpose.
- Website URL: The primary URL of your application.
- Redirect URI(s): Crucially, these are the URLs to which Dailymotion will redirect the user after they grant or deny authorization. For security, these must be exact matches to the URIs used in your OAuth requests. You can register multiple redirect URIs for different environments (e.g., development, staging, production).
- Permissions (Scopes): Select the API scopes (permissions) your application requires. Examples include
read,write,manage_videos,manage_channels. Only request the minimum necessary permissions.
-
Retrieve Client ID and Client Secret: After successful registration, Dailymotion will issue your unique Client ID and Client Secret. The Client ID is publicly exposed and used to identify your app in authorization requests. The Client Secret is a sensitive credential and must be kept confidential, similar to a password. It is used to authenticate your application when exchanging authorization codes for access tokens.
It's vital to store your Client Secret securely and never embed it directly into client-side code (e.g., JavaScript). For server-side applications, use environment variables or a secure configuration management system to store this secret.
Authenticated request example
This example demonstrates how to make an authenticated request using an access token obtained via the OAuth 2.0 Authorization Code flow. After your application has successfully completed the OAuth flow and received an access token, you can include it in the Authorization header of your API requests.
Let's assume you have obtained an ACCESS_TOKEN and want to retrieve information about the currently authenticated user's account.
GET /me?fields=id,username,email HTTP/1.1
Host: api.dailymotion.com
Authorization: Bearer YOUR_ACCESS_TOKEN
In this example:
GET /me?fields=id,username,emailis the API endpoint to retrieve details for the authenticated user, specifying desired fields.Host: api.dailymotion.comspecifies the Dailymotion API domain.Authorization: Bearer YOUR_ACCESS_TOKENis the HTTP header whereYOUR_ACCESS_TOKENshould be replaced with the actual access token obtained from the OAuth flow. TheBearerscheme is the standard for OAuth 2.0 tokens.
The Dailymotion API documentation provides an interactive API explorer where you can experiment with authenticated requests and various endpoints.
Security best practices
Adhering to security best practices is paramount when implementing Dailymotion API authentication to protect both your application and user data.
-
Protect Your Client Secret: Treat your Client Secret as you would a password. Never hardcode it into client-side code, commit it to public version control repositories, or expose it in browser requests. Store it securely on your server, preferably using environment variables or a dedicated secret management service.
-
Use HTTPS Everywhere: Always use HTTPS for all communication with Dailymotion's API endpoints and for your application's redirect URIs. This encrypts data in transit, protecting sensitive information like authorization codes and access tokens from interception. The OAuth 2.0 specification (RFC 6749 Section 1.6) explicitly recommends the use of TLS (Transport Layer Security) for all communications.
-
Validate Redirect URIs: Register specific, authorized redirect URIs in your Dailymotion application settings. During the OAuth flow, Dailymotion will only redirect users to these pre-registered URLs. This prevents attackers from redirecting users to malicious sites to capture authorization codes or tokens. Ensure that you validate the
redirect_uriparameter in your authorization requests against your registered URIs. -
Request Minimum Scopes: Follow the principle of least privilege. Request only the minimum necessary API scopes (permissions) your application needs to function. This limits the potential damage if your application's access token is compromised.
-
Securely Store Access and Refresh Tokens: Access tokens grant immediate access to resources and should be stored securely on your server. Refresh tokens, which allow your application to obtain new access tokens without re-prompting the user, are even more sensitive as they typically have a longer lifespan. Store them encrypted and revoke them immediately if compromise is suspected.
-
Implement Token Refresh Rotation: If Dailymotion supports refresh token rotation (issuing a new refresh token with each new access token), implement this feature. This enhances security by limiting the lifespan of any single refresh token.
-
Handle Errors Gracefully: Implement robust error handling for authentication failures, including expired tokens, invalid scopes, or revoked access. Provide clear, user-friendly messages without exposing sensitive technical details.
-
Regularly Audit and Monitor: Periodically review your application's access logs and Dailymotion's developer portal for any unusual activity. Stay informed about Dailymotion's API security updates and best practices.