Authentication overview

Tomorrow's Weather API utilizes API keys as its primary method for authenticating requests. This mechanism ensures that only authorized applications and users can access the various weather data endpoints, including real-time forecasts, historical data, and air quality information. Each request sent to the Tomorrow API must include a valid API key for successful processing and to identify the user's subscription plan and access permissions.

An API key acts as a unique identifier and a secret token that grants access to an API. When a client makes a request, the API key is transmitted, allowing the server to verify the client's identity and determine their authorized scope. This method is widely adopted for its simplicity and effectiveness in managing access to web services. The Tomorrow API documentation provides detailed guidance on authenticating API requests.

Security for API key transmission is managed through HTTPS, which encrypts the communication channel between the client and the Tomorrow servers. This prevents attackers from intercepting and compromising the API key during transit. Developers are responsible for securely storing and managing their API keys on their end to prevent unauthorized access.

Supported authentication methods

Tomorrow exclusively supports API key authentication for its various API services. This approach simplifies the authentication process for developers while providing a secure mechanism for access control. The API key is typically passed as a query parameter in the request URL.

API Key Authentication

API key authentication involves embedding a unique, secret key directly within each API request. This key identifies the calling application or user and grants access based on the associated permissions. For Tomorrow, this key links to your account and its subscribed plan, determining the available endpoints and rate limits. The Tomorrow API authentication guide details how to include the key in your requests.

The table below summarizes the characteristics of Tomorrow's supported authentication method:

Method When to Use Security Level
API Key All API interactions with Tomorrow's Weather API. Suitable for server-side applications, mobile apps, and web frontends where keys can be securely managed. Moderate (Requires secure key storage and HTTPS for transmission)

While API keys are a common and effective method, it's crucial to understand their limitations compared to more complex schemes like OAuth 2.0 authorization flows. API keys provide authentication but not authorization delegation, meaning they grant direct access rather than mediated, user-consented access. Therefore, proper key management is paramount.

Getting your credentials

To access the Tomorrow Weather API, you must first obtain an API key from your Tomorrow account dashboard. The process generally involves signing up for an account, selecting a plan (including the free Developer Plan), and then generating the key.

  1. Sign Up or Log In: Navigate to the Tomorrow website and either create a new account or log in to an existing one.
  2. Access API Settings: Once logged in, locate the API settings or dashboard section. This is typically found under a profile or developer-specific menu.
  3. Generate API Key: Within the API settings, there should be an option to generate a new API key. Follow the prompts to create your key. Tomorrow allows users to generate and manage multiple API keys, which can be useful for different projects or environments (e.g., development, staging, production).
  4. Copy and Securely Store Key: After generation, the API key will be displayed. It is critical to copy this key immediately and store it in a secure location. For security reasons, the key may only be displayed once. Never hardcode API keys directly into client-side code or public repositories.
  5. Monitor Usage: The dashboard also provides tools to monitor your API usage, which is essential for staying within your plan limits and identifying any unusual activity.

For detailed, step-by-step instructions on key generation and management, refer to the Tomorrow quickstart guide.

Authenticated request example

Once you have obtained your API key, you can include it in your API requests. The Tomorrow API expects the API key to be passed as a query parameter named apikey. Here are examples in cURL, Python, and Node.js for requesting weather data for a specific location.

cURL Example

This cURL command demonstrates a basic request to the Tomorrow Weather API's forecast endpoint, including the API key:

curl "https://api.tomorrow.io/v4/weather/forecast?location=42.3478,-71.0466&apikey=YOUR_API_KEY"

Python Example

Using the requests library in Python, you can construct and send an authenticated request:

import requests

api_key = "YOUR_API_KEY"
location = "42.3478,-71.0466" # Latitude, Longitude (e.g., Boston, MA)
url = f"https://api.tomorrow.io/v4/weather/forecast?location={location}&apikey={api_key}"

response = requests.get(url)

if response.status_code == 200:
    print("Success!")
    print(response.json())
else:
    print(f"Error: {response.status_code}")
    print(response.text)

Node.js Example

Here's how to make an authenticated request using Node.js with the built-in https module or a library like axios:

const axios = require('axios');

const apiKey = 'YOUR_API_KEY';
const location = '42.3478,-71.0466'; // Latitude, Longitude
const url = `https://api.tomorrow.io/v4/weather/forecast?location=${location}&apikey=${apiKey}`;

axios.get(url)
  .then(response => {
    console.log('Success!');
    console.log(response.data);
  })
  .catch(error => {
    console.error(`Error: ${error.response ? error.response.status : error.message}`);
    if (error.response) {
      console.error(error.response.data);
    }
  });

Remember to replace YOUR_API_KEY with your actual API key and adjust the location parameter as needed for your specific use case. The Tomorrow API reference provides comprehensive details on available endpoints and parameters.

Security best practices

Securing your API keys is crucial to prevent unauthorized access to your Tomorrow account and potential misuse of your API quota. Adhering to these best practices will help maintain the integrity and confidentiality of your credentials.

  • Never Expose API Keys in Client-Side Code: Do not embed API keys directly in publicly accessible client-side code (e.g., JavaScript in a web browser, mobile app bundles). If your application requires a key on the client, consider using a proxy server to make requests, or implement a backend service that calls the Tomorrow API on behalf of your client, handling authentication securely on the server-side.
  • Store API Keys Securely: For server-side applications, store API keys in environment variables, dedicated configuration files that are not committed to version control, or secure secret management services (e.g., AWS Secrets Manager, Azure Key Vault, Google Secret Manager). Avoid hardcoding keys directly into your source code.
  • Use HTTPS Always: All communications with the Tomorrow API should occur over HTTPS. This encrypts your API key and data in transit, protecting against eavesdropping and man-in-the-middle attacks. Tomorrow's API endpoints are exclusively served over HTTPS, eliminating the need for explicit configuration on your part, but it's a fundamental principle of Transport Layer Security (TLS).
  • Implement Least Privilege: While Tomorrow's API keys typically grant access to all endpoints based on your plan, consider if you can structure your application to minimize the exposure of the key. If Tomorrow introduces more granular key permissions in the future, apply the principle of least privilege by granting only the necessary permissions.
  • Rotate API Keys Regularly: Periodically rotate your API keys. This practice reduces the window of opportunity for a compromised key to be exploited. If you suspect a key has been compromised, revoke it immediately through your Tomorrow dashboard and generate a new one.
  • Monitor API Usage: Regularly check your API usage statistics in the Tomorrow dashboard. Unusual spikes in requests or access patterns could indicate a compromised key.
  • IP Whitelisting (if available): If Tomorrow offers IP whitelisting capabilities (restricting API key usage to specific IP addresses), utilize this feature to add an extra layer of security. This ensures that even if a key is stolen, it can only be used from authorized servers. Currently, Tomorrow's documentation does not explicitly mention IP whitelisting for API keys, but it is a general best practice to look for.