Authentication overview
Authentication for Rig Veda APIs establishes the identity of a client or user attempting to access protected resources. This process ensures that only authorized entities can interact with the API, thereby protecting data and maintaining system integrity. Rig Veda supports industry-standard authentication mechanisms designed to accommodate various integration scenarios, from server-side applications to client-side user interactions.
The choice of authentication method typically depends on the application's nature, the level of access required, and the security context. For direct server-to-server communication where a client application acts on its own behalf, API keys are often employed. When an application needs to access a user's data with their explicit consent, the OAuth 2.0 authorization framework is utilized to delegate limited access without sharing user credentials directly.
Supported authentication methods
Rig Veda offers distinct authentication methods to address different use cases and security requirements. Understanding the characteristics of each method is crucial for implementing secure and functional API integrations.
API Key
API keys are unique identifiers used to authenticate an application or project accessing the Rig Veda API. They are typically provided as a simple string that the client includes in each API request. API keys are suitable for server-to-server communication or applications where a single client identity is sufficient and user context is not required. It is important to treat API keys as sensitive credentials, similar to passwords, due to the direct access they grant.
When to use API Keys:
- Backend services making requests on their own behalf.
- Applications requiring direct, programmatic access without user interaction.
- Simple integrations where granular user permissions are not necessary.
OAuth 2.0
OAuth 2.0 is an authorization framework that enables an application to obtain limited access to a user's protected resources on an HTTP service, with the user's explicit consent. Rig Veda implements OAuth 2.0 to facilitate secure delegated access, ensuring that user credentials are not exposed to the client application. This method is crucial for applications that operate on behalf of users, such as third-party services integrating with a user's Rig Veda account.
The OAuth 2.0 flow typically involves several steps: the application requests authorization from the user, the user grants permission, and the application receives an access token. This access token is then used to make authenticated requests to the Rig Veda API on behalf of the user. Refresh tokens are often provided alongside access tokens to allow applications to obtain new access tokens without re-prompting the user for authorization after the initial access token expires, as detailed in the OAuth 2.0 Authorization Framework specification.
When to use OAuth 2.0:
- External applications accessing user-specific data with user consent.
- Client-side applications (e.g., mobile apps, single-page applications) where API keys might be exposed.
- Scenarios requiring granular control over permissions (scopes).
The table below summarizes the supported authentication methods:
| Method | When to Use | Security Level |
|---|---|---|
| API Key | Server-to-server communication, backend services, programmatic access. | Moderate (requires secure storage and transmission). |
| OAuth 2.0 | Third-party applications accessing user data with consent, client-side applications. | High (delegated access, token-based, scopes). |
Getting your credentials
To begin authenticating with Rig Veda, you must first obtain the necessary credentials. The process varies depending on the chosen authentication method.
For API Keys:
- Log into the Rig Veda Developer Portal: Navigate to your account dashboard.
- Access API Key Management: Locate the section dedicated to API keys, usually labeled "API Keys" or "Credentials."
- Generate a New API Key: Follow the prompts to create a new API key. You may be asked to assign a name or associate it with a specific project for better organization.
- Record Your API Key: Once generated, the API key will be displayed. It is critical to copy and store this key securely immediately, as it may not be retrievable later for security reasons.
For OAuth 2.0:
- Register Your Application: In the Rig Veda Developer Portal, register your application. This process typically requires providing an application name, description, and one or more redirect URIs. The redirect URIs are essential as they inform Rig Veda where to send the user back after they authorize your application.
- Obtain Client ID and Client Secret: Upon successful registration, Rig Veda will issue a Client ID and Client Secret for your application. The Client ID is public and identifies your application, while the Client Secret must be kept confidential and is used to authenticate your application to Rig Veda's authorization server.
- Configure Redirect URIs: Ensure your application's redirect URIs are correctly configured in both your application and the Rig Veda Developer Portal. Mismatched URIs will prevent the OAuth flow from completing successfully. The Google Identity OAuth 2.0 documentation provides a general overview of these concepts.
Authenticated request example
This section provides examples of how to include your authentication credentials in API requests to Rig Veda, demonstrating typical usage for both API keys and OAuth 2.0.
API Key Example (HTTP Header)
When using an API key, it is generally recommended to transmit it in an HTTP header rather than as a URL query parameter, to reduce the risk of it being logged in server access logs or browser history. Rig Veda typically expects API keys in an X-API-Key or Authorization header.
curl -X GET \
'https://api.rigveda.com/v1/resources' \
-H 'X-API-Key: YOUR_RIGVEDA_API_KEY' \
-H 'Content-Type: application/json'
Replace YOUR_RIGVEDA_API_KEY with the actual API key obtained from your Rig Veda Developer Portal.
OAuth 2.0 Example (Bearer Token)
For OAuth 2.0, after your application successfully completes the authorization flow and obtains an access token, it includes this token in the Authorization header using the Bearer scheme for subsequent API requests.
curl -X POST \
'https://api.rigveda.com/v1/user-data' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{ "field": "value" }'
Replace YOUR_ACCESS_TOKEN with the valid access token issued by Rig Veda's OAuth server. Access tokens have a limited lifespan and will need to be refreshed using a refresh token when they expire, if your initial OAuth flow provided one.
Security best practices
Maintaining the security of your authentication credentials and API interactions is paramount. Adhering to these best practices will help protect your applications and data when integrating with Rig Veda.
- Protect API Keys and Client Secrets: Treat API keys and OAuth client secrets as highly sensitive information.
- Never hardcode them: Store them in environment variables, secret management services (e.g., AWS Secrets Manager, Google Secret Manager), or secure configuration files.
- Do not commit to version control: Ensure they are excluded from your source code repositories (e.g., using
.gitignore). - Restrict access: Limit who has access to these credentials within your organization.
- Use HTTPS/TLS: All communication with Rig Veda APIs must occur over HTTPS (TLS). This encrypts data in transit, preventing eavesdropping and tampering. Rig Veda APIs enforce HTTPS, rejecting unencrypted HTTP requests, which is a standard security measure as described in the IETF RFC 7230 on HTTP/1.1 Message Syntax and Routing.
- Implement Least Privilege: When generating API keys or configuring OAuth scopes, grant only the minimum necessary permissions for your application to function. Avoid granting broad or unnecessary access.
- Regularly Rotate Credentials: Periodically rotate your API keys and client secrets. This practice limits the window of exposure if a credential is ever compromised.
- Monitor API Usage: Keep an eye on your API usage logs for unusual activity that might indicate unauthorized access or misuse of your credentials. Rig Veda provides logging and monitoring tools within its developer portal.
- Secure OAuth Redirect URIs: For OAuth 2.0, register only highly specific and secure redirect URIs. Avoid using
localhostor broad wildcards in production environments. Ensure your redirect URI handles the incoming authorization code securely and is protected against cross-site request forgery (CSRF) attacks. - Handle Tokens Securely:
- Access Tokens: Store access tokens securely in memory for the duration of their validity, and avoid persisting them unnecessarily.
- Refresh Tokens: If using refresh tokens, store them even more securely, as they can be used to obtain new access tokens. Encrypt them at rest and restrict their access.
- Error Handling: Implement robust error handling for authentication failures. Avoid leaking sensitive information in error messages.