Authentication overview
Authentication for the Loqate API ensures that only authorized applications and users can access its address, email, and phone verification services. The Loqate API uses a straightforward authentication model, primarily relying on API keys to validate requests. This method is common for web services where simplicity and ease of integration are priorities, particularly for server-to-server communication or backend applications.
When an application sends a request to a Loqate API endpoint, it must include a valid API key. The API key serves as a unique identifier for your account and authorizes the request. Without a correct and active API key, the Loqate API will reject the request, preventing unauthorized access and ensuring the integrity of the services. This system helps manage usage, enforce rate limits, and attribute requests to specific accounts for billing and analytics purposes, as detailed in the Loqate Address Verification API reference.
Supported authentication methods
The Loqate API primarily supports API key authentication. This method involves including a unique key in each API request to identify and authenticate the calling application. API keys are suitable for identifying projects and clients, and are generally simpler to implement than more complex authentication flows like OAuth 2.0 for many backend-to-backend API interactions.
API Key
API keys are long, alphanumeric strings that you generate from your Loqate account dashboard. They are used to grant access to your Loqate services and track your usage. When using an API key, it is typically passed as a query parameter in the URL of your API requests. For example, a request might look like https://api.loqate.com/api/v1/address?key=YOUR_API_KEY&text=123 Main St.
While API keys offer simplicity, their security relies heavily on proper handling and protection. They should be treated like passwords and never exposed in client-side code or public repositories. The Loqate documentation emphasizes the importance of keeping API keys confidential.
Authentication Method Comparison
The table below outlines the primary authentication method supported by the Loqate API, along with its typical use cases and security considerations.
| Method | When to Use | Security Level |
|---|---|---|
| API Key | Server-side applications, backend services, internal tools, scripts where key can be securely stored. | Moderate (dependent on secure key management). Requires HTTPS. |
Getting your credentials
To authenticate with the Loqate API, you will need to obtain an API key from your Loqate account. The process typically involves registering for an account and generating a key through their online portal.
- Create a Loqate Account: If you do not already have one, sign up for a Loqate account on their official website. Loqate offers a free tier that includes 100 lookups per month, which is sufficient for initial testing and development.
- Access Your Dashboard: Log in to your Loqate account dashboard.
- Navigate to API Key Management: Look for a section related to 'API Keys', 'My Keys', or 'Developer Settings'. The exact navigation path may vary slightly but is typically found under your account settings or a dedicated developer portal within the dashboard.
- Generate a New API Key: Follow the instructions to generate a new API key. Some platforms allow you to name your keys for easier management, especially if you plan to use different keys for different applications or environments (e.g., development, staging, production).
- Copy Your API Key: Once generated, your API key will be displayed. Copy this key immediately and store it securely. Loqate, like many API providers, may only display the full key once upon creation for security reasons.
It is recommended to generate separate API keys for different applications or environments to enhance security and simplify key rotation and revocation, as advised in general API security practices by organizations such as the IETF RFC 6750 for Bearer Token usage, which shares similar security principles with API key management.
Authenticated request example
Once you have obtained your API key, you can include it in your API requests. The Loqate API typically expects the API key to be passed as a query parameter named key. Below is an example of an authenticated request using curl, a common command-line tool for making HTTP requests.
Example: Address Verification Request
This example demonstrates how to make a request to the Loqate Address Verification API to find an address, including your API key.
curl "https://api.loqate.com/capture/address/v2/find?key=YOUR_API_KEY&text=100 Main Street, London&country=GB"
In this example:
YOUR_API_KEYshould be replaced with the actual API key you obtained from your Loqate account.textis the address string you want to verify or find.countryspecifies the country for the address search.
Always ensure that your API key is correctly inserted into the request URL. For more detailed examples and available parameters, refer to the specific endpoint documentation within the Loqate Address Verification API reference.
Security best practices
Securing your API keys and ensuring the integrity of your interactions with the Loqate API is critical. Adhering to these best practices can help prevent unauthorized access, data breaches, and misuse of your account.
1. Keep API Keys Confidential
- Never embed keys directly in client-side code: Do not hardcode API keys into JavaScript, mobile applications, or any code that runs on a user's device, as they can be easily extracted.
- Store keys securely: Store API keys in environment variables, secret management services (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault), or secure configuration files on your server. Avoid committing them to version control systems like Git, even in private repositories.
- Use HTTPS: All communication with the Loqate API should occur over HTTPS (HTTP Secure). This encrypts the data in transit, protecting your API key and other sensitive information from interception. Loqate API endpoints are served exclusively over HTTPS.
2. Restrict Key Usage (if applicable)
While Loqate's API key system is generally broad, if future updates or specific keys allow for restrictions, consider:
- IP Address Restrictions: If your API key management system allows, restrict API key usage to specific IP addresses or ranges from which your server-side applications make requests. This adds an extra layer of security, ensuring that even if a key is compromised, it can only be used from authorized locations.
- Referrer Restrictions: For keys used in web applications (though not recommended for Loqate's primary server-side use case), restrict usage to specific website domains.
3. Implement Key Rotation
Regularly rotate your API keys. This means generating a new key, updating your applications to use the new key, and then revoking the old key. Frequent rotation limits the window of opportunity for a compromised key to be exploited. A common practice is to rotate keys every 90 days or whenever there is a change in personnel who had access to the keys.
4. Monitor Usage and Logs
Regularly review your Loqate API usage reports and logs for unusual activity. Spikes in usage, requests from unexpected geographical locations, or frequent authentication failures could indicate a compromised key or malicious activity. Loqate's dashboard provides tools to monitor your consumption.
5. Error Handling and Rate Limiting
Implement robust error handling in your application to gracefully manage authentication failures. Be aware of Loqate's rate limits and implement retry mechanisms with exponential backoff to avoid being temporarily blocked. While not directly an authentication security measure, proper error handling and rate limiting contribute to the overall stability and security posture of your integration by preventing denial-of-service scenarios and managing resource consumption efficiently.
6. Revoke Compromised Keys Immediately
If you suspect an API key has been compromised, revoke it immediately through your Loqate account dashboard. After revocation, generate a new key and update your applications accordingly. Prompt action is crucial to minimize potential damage from a security incident.
By following these best practices, developers can significantly enhance the security of their Loqate API integrations and protect their data and services. The AWS documentation on managing access keys provides further general guidance on secure credential management that applies broadly to API keys.