Authentication overview

Cartes.io employs a straightforward authentication mechanism centered around API keys. This method provides a direct way to authorize access to its geocoding, reverse geocoding, and search APIs. An API key serves as a secret token that identifies your application and verifies its permission to make requests. When a request is made to the Cartes.io API, the provided key is checked against registered keys to determine if the request is legitimate and if the associated account has sufficient quota or permissions for the requested operation. This approach is common among many web APIs due to its simplicity and ease of integration, particularly for developers integrating geospatial services into their applications.

The use of API keys allows Cartes.io to monitor usage, enforce rate limits, and manage access control for individual users or applications. While simple, the security of this method heavily depends on how developers manage and protect their API keys, as an exposed key could lead to unauthorized usage and potential quota exhaustion. Understanding the proper handling and application of these keys is fundamental for secure and efficient integration with Cartes.io services.

Supported authentication methods

Cartes.io primarily supports API key authentication. This method is used across all its API endpoints to secure access and identify the requesting application. The API key is passed as a query parameter in each API request. There are no other explicit authentication methods like OAuth 2.0 or HTTP Basic Authentication detailed in the official Cartes.io API documentation for general use.

API Key

API key authentication involves appending a unique alphanumeric string to your API requests. This key is generated for your account and acts as your credential for accessing Cartes.io services. It is essential for tracking usage and enforcing any rate limits or subscription tiers associated with your account. For example, the free tier allows up to 5,000 requests per month, which is tracked via the API key Cartes.io pricing details.

When using API keys, it's crucial to understand their security implications. Unlike token-based authentication methods like OAuth 2.0, which often have short-lived tokens and refresh mechanisms, API keys are typically long-lived credentials. This makes their secure storage and transmission paramount. Compromised API keys can lead to unauthorized access to your quota, potentially incurring costs or service interruptions if limits are exceeded.

Authentication Method Comparison

Method When to Use Security Level
API Key (Query Parameter) Server-side applications, limited client-side use with strict domain restrictions Medium (requires careful management)

Getting your credentials

To obtain your Cartes.io API key, you typically need to register for an account on the Cartes.io website. After successful registration, your API key will be available in your user dashboard or account settings. The process generally involves these steps:

  1. Sign Up/Log In: Navigate to the Cartes.io homepage and either create a new account or log in to an existing one.
  2. Access Dashboard: Once logged in, locate your personal dashboard or account management section.
  3. Retrieve API Key: Within the dashboard, there should be a dedicated section for API keys or developer settings where your unique key is displayed. Cartes.io's API documentation notes that the key is provided upon account creation Cartes.io API reference.

It is recommended to copy your API key directly from the dashboard and store it securely. Avoid hardcoding API keys directly into client-side code that is exposed to the public, such as JavaScript in a web browser, unless specific domain restrictions are applied to the key. For server-side applications, store the key in environment variables or a secure configuration management system rather than directly in your source code.

Authenticated request example

Cartes.io API keys are passed as a query parameter named key in your HTTP requests. Below is an example of how to make an authenticated request using curl to a geocoding endpoint. Replace YOUR_API_KEY with your actual Cartes.io API key and adjust the address parameter as needed.

curl "https://api.cartes.io/geocode?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY"

In this example, the key=YOUR_API_KEY portion of the URL is how you authenticate your request. For client-side JavaScript applications, you would construct the URL similarly:

const apiKey = 'YOUR_API_KEY';
const address = 'Eiffel Tower, Paris';
const url = `https://api.cartes.io/geocode?address=${encodeURIComponent(address)}&key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

When implementing this in a server-side application, such as Node.js or Python, you would typically retrieve the API key from an environment variable to enhance security. This prevents the key from being committed to version control systems.

Security best practices

Securing your Cartes.io API key is critical to prevent unauthorized usage and potential misuse of your account's quota. Adhering to these best practices will help maintain the integrity of your integration:

  • Do Not Embed Keys in Client-Side Code: Avoid hardcoding your API key directly into publicly accessible client-side code (e.g., JavaScript in a web browser). If the key is exposed, anyone can use it, potentially depleting your quota. If client-side use is unavoidable, implement strong domain restrictions on your API key from the Cartes.io dashboard, if available, or consider using a proxy server to abstract the key.

  • Use Environment Variables for Server-Side Keys: For server-side applications, store your API key in environment variables rather than directly in your source code. This practice prevents the key from being exposed in version control systems and allows for easier rotation and management across different deployment environments. This is a common security practice for API keys across many platforms, as documented by Google API key best practices.

  • Restrict API Key Usage: If Cartes.io offers features to restrict API key usage (e.g., by IP address, HTTP referrer, or specific API endpoints), configure these restrictions. This limits the impact of a compromised key by ensuring it can only be used from authorized sources or for specific purposes.

  • Regularly Rotate Keys: Periodically generate new API keys and revoke old ones. This practice reduces the window of opportunity for a compromised key to be exploited. The frequency of rotation depends on your security policy and the sensitivity of your application.

  • Monitor Usage: Regularly check your Cartes.io dashboard for API usage patterns. Unusual spikes in requests could indicate that your API key has been compromised. Promptly investigate any suspicious activity.

  • Secure Transmission: Always use HTTPS to make requests to the Cartes.io API. This encrypts the communication between your application and the API server, preventing eavesdropping and protecting your API key from being intercepted during transit. The IETF's RFC 7230 specifies that HTTP/1.1 messages are transported over TCP, and HTTPS adds a layer of security via TLS/SSL HTTP/1.1 Message Syntax and Routing.

  • Implement Server-Side Validation: If your application involves user input that interacts with the Cartes.io API, ensure that all input is properly validated and sanitized on the server side to prevent injection attacks or malformed requests that could bypass security measures.