Authentication overview

Authentication for Hackerearth's platform enables secure programmatic access to its services, primarily for integrating technical assessment and hiring workflows. This allows authorized applications and users to interact with features such as creating tests, managing candidates, and retrieving assessment results. The choice of authentication method depends on the specific use case, ranging from direct API key usage for server-to-server communication to OAuth 2.0 for third-party application integration.

Hackerearth's authentication mechanisms are designed to protect user data and ensure that only authorized entities can perform actions or access sensitive information. Adherence to standard security protocols, such as HTTPS/TLS for all API communications, is fundamental to maintaining the integrity and confidentiality of data exchanged with the platform. Developers are advised to consult the Hackerearth support portal for the most current and detailed documentation on API access and authentication specifics.

Supported authentication methods

Hackerearth supports several authentication methods to accommodate various integration scenarios. The primary method for direct programmatic access is through API keys, while OAuth 2.0 is available for more complex third-party application integrations requiring delegated authorization.

API Key Authentication

API key authentication is a straightforward method primarily used for server-to-server communication or when an application needs direct access to Hackerearth's APIs with a single, predefined identity. An API key is a unique token that identifies the calling application or user account. When making requests, this key is typically included in the request headers, often as a bearer token or a custom header. This method provides a direct way to authenticate but requires careful management of the key to prevent unauthorized access.

OAuth 2.0

OAuth 2.0 is an authorization framework that enables third-party applications to obtain limited access to a user's resources on an HTTP service, without exposing the user's credentials. This is particularly useful for applications that need to interact with Hackerearth on behalf of a user, such as an applicant tracking system integrating with Hackerearth to manage candidate assessments. OAuth 2.0 involves a more complex flow, typically involving redirections and the exchange of authorization codes for access tokens. The access tokens grant temporary, scoped permissions, enhancing security by limiting potential damage if a token is compromised.

The OAuth 2.0 framework is widely adopted across web services, including platforms like Google's Identity Platform and the OAuth community site, providing a standardized approach to delegated authorization.

Authentication Methods Summary

The following table summarizes the primary authentication methods available for Hackerearth:

Method When to Use Security Level
API Key Server-to-server communication, internal tools, direct API calls Medium (requires secure key management)
OAuth 2.0 Third-party integrations, delegated authorization, user consent required High (token-based, temporary, scoped access)

Getting your credentials

To begin integrating with Hackerearth and authenticating your requests, you will need to obtain the appropriate credentials. For most programmatic integrations, this involves generating an API key or setting up an OAuth 2.0 application.

For API Keys

  1. Log in to your Hackerearth account: Access your organizational or individual account on the Hackerearth platform.
  2. Navigate to API Settings: Look for a section related to API access, integrations, or developer settings, typically found within your account or organization dashboard. The exact path may vary, so refer to the Hackerearth support documentation for the precise location.
  3. Generate a new API key: Within the API settings, you should find an option to generate a new API key. It's common practice to label your API keys for better organization and to understand their purpose later.
  4. Securely store your API key: Once generated, the API key will typically be displayed only once. Copy it immediately and store it in a secure location, such as an environment variable or a secrets management system. Do not hardcode API keys directly into your application code or expose them in public repositories.
  5. Configure permissions (if applicable): Some platforms allow granular control over API key permissions. Ensure your key has only the necessary permissions required for your integration to adhere to the principle of least privilege.

For OAuth 2.0 Client Credentials

Setting up OAuth 2.0 requires registering your application with Hackerearth to obtain client credentials (Client ID and Client Secret) and configure redirect URIs.

  1. Register your application: In your Hackerearth account's developer or integration settings, you will need to register a new OAuth application. This process typically involves providing an application name, description, and at least one redirect URI.
  2. Obtain Client ID and Client Secret: Upon successful registration, Hackerearth will provide you with a Client ID and Client Secret. The Client ID is public, but the Client Secret must be kept confidential, similar to an API key.
  3. Configure Redirect URIs: The redirect URI(s) are crucial for the OAuth flow. They specify where Hackerearth should redirect the user's browser after they authorize your application. These URIs must exactly match the ones registered with Hackerearth.
  4. Define Scopes: During registration or when requesting authorization, you will specify the scopes (permissions) your application needs. For example, access to candidate profiles or assessment results. Request only the minimum necessary scopes.
  5. Implement the OAuth flow: Your application will need to implement the chosen OAuth 2.0 grant type (e.g., Authorization Code flow) to exchange an authorization code for an access token and refresh token. The access token is then used to make API calls on behalf of the user.

Authenticated request example

While specific API endpoints and request structures vary, an authenticated request using an API key typically involves including the key in the HTTP header. Below is a conceptual example using curl for an API request that might retrieve details about an assessment. Note that this is a placeholder and would need to be adapted to specific Hackerearth API endpoints and parameters.


curl -X GET \
  'https://api.hackerearth.com/v1/assessments/{assessment_id}' \
  -H 'Authorization: Bearer YOUR_API_KEY'

In this example:

  • -X GET specifies the HTTP method (GET for retrieving data).
  • 'https://api.hackerearth.com/v1/assessments/{assessment_id}' is the hypothetical API endpoint to retrieve assessment details. You would replace {assessment_id} with an actual assessment identifier.
  • -H 'Authorization: Bearer YOUR_API_KEY' is the header that carries the API key. Bearer is a common scheme for token-based authentication. You would replace YOUR_API_KEY with your actual API key obtained from your Hackerearth account.

For OAuth 2.0, after successfully completing the authorization flow and obtaining an access token, subsequent API requests would include this access token in a similar Authorization: Bearer <ACCESS_TOKEN> header. The specifics of the access token acquisition are detailed in RFC 6749, The OAuth 2.0 Authorization Framework.

Security best practices

Securing your Hackerearth integrations requires adherence to general API security best practices. Proper management of credentials and careful implementation of authentication flows are critical to protecting sensitive data and preventing unauthorized access.

Protect API Keys and Client Secrets

  • Never hardcode credentials: Do not embed API keys or client secrets directly into your application's source code. Use environment variables, configuration files that are not committed to version control, or a dedicated secrets management service.
  • Restrict access: Limit who has access to your API keys and client secrets within your organization. Implement role-based access control (RBAC) to ensure only authorized personnel can retrieve or manage these credentials.
  • Avoid public exposure: Ensure that your application's front-end code (client-side JavaScript) does not expose API keys. All API calls requiring confidential credentials should be made from a secure backend server.
  • Rotate keys regularly: Periodically generate new API keys and revoke old ones. This practice reduces the window of opportunity for a compromised key to be exploited.

Implement Secure OAuth 2.0 Flows

  • Use HTTPS for all communications: Ensure all interactions, especially redirects and token exchanges, occur over HTTPS (TLS). This encrypts data in transit, preventing eavesdropping.
  • Validate redirect URIs: Always register and strictly validate redirect URIs to prevent redirection attacks. Ensure that the redirect_uri parameter in your authorization requests matches exactly what is registered with Hackerearth.
  • Implement PKCE (Proof Key for Code Exchange) for public clients: For mobile and single-page applications (public clients), PKCE is essential to mitigate authorization code interception attacks. PKCE adds a dynamically generated secret to the authorization code flow.
  • Request minimal scopes: Follow the principle of least privilege by requesting only the necessary permissions (scopes) for your application to function. Do not request broad access if only specific actions are needed.
  • Securely store refresh tokens: If your application uses refresh tokens to obtain new access tokens without re-authenticating the user, store them securely. They should be treated with the same level of confidentiality as API keys.

General Security Measures

  • Monitor API usage: Keep an eye on your API usage patterns. Unusual spikes or requests from unexpected locations could indicate unauthorized activity.
  • Error handling: Implement robust error handling without exposing sensitive information in error messages. Generic error messages are preferable to detailed ones that might aid an attacker.
  • Stay updated: Keep your libraries, frameworks, and server software updated to patch known security vulnerabilities.
  • Review Hackerearth's security guidelines: Consult the official Hackerearth support documentation for any specific security recommendations or requirements they provide.