Authentication overview

MY IP secures access to its API endpoints using API keys. This method requires developers to include a unique, secret key with each request to verify their identity and authorize access to API resources. The API key serves as a credential that links requests to your account, enabling MY IP to manage usage allowances, apply rate limits, and ensure proper billing according to your subscription plan. This approach is common for RESTful APIs where simplicity and ease of integration are priorities, particularly for services like IP address lookups and basic geolocation data.

MY IP's API supports both HTTP and HTTPS, though HTTPS is strongly recommended for all production environments to encrypt data in transit and protect API keys from interception. The API is designed for direct server-to-server communication or client-side applications where the API key can be securely managed. For detailed information on API functionality and available endpoints, refer to the MY IP API documentation.

Supported authentication methods

MY IP primarily utilizes API key authentication. This method is straightforward and widely adopted for web services that do not require complex authorization flows like OAuth 2.0. The API key acts as a secret token that must be presented with each request.

Method When to Use Security Level
API Key (Query Parameter) Server-side applications, scripts, or when quick integration is prioritized. Moderate (Requires secure handling; vulnerable if exposed in client-side code).
API Key (Header) Server-side applications, microservices, or environments where headers can be securely managed. Moderate (Slightly more secure than query parameters as it's less prone to logging in URLs).

While API keys offer simplicity, it's crucial to implement them with security best practices to prevent unauthorized access to your account. For scenarios requiring user consent or delegated access to third-party applications, a more robust framework like OAuth 2.0 would typically be employed. However, for direct application access to MY IP's services, API keys are sufficient and appropriate.

Getting your credentials

To authenticate with the MY IP API, you first need to obtain an API key. This key is provisioned upon successful registration and can be accessed through your user dashboard.

  1. Register for an account: Navigate to the MY IP homepage and complete the registration process. This typically involves providing an email address and creating a password.
  2. Access your dashboard: After registration, log into your MY IP account. Your dashboard is the central place for managing your account, subscriptions, and API keys.
  3. Locate your API key: Within the dashboard, there will be a dedicated section for API access or API keys. Your unique API key will be displayed there. It's usually a long string of alphanumeric characters.
  4. Copy your API key: Securely copy this key. It is crucial to treat your API key as a sensitive credential, similar to a password.

MY IP typically generates one primary API key per account. If you need to revoke or regenerate your key (e.g., in case of a security incident), these options are usually available within the same API key management section of your dashboard. Always refer to the official MY IP documentation for the most up-to-date instructions on credential management.

Authenticated request example

MY IP's API key is typically passed as a query parameter in your requests. Here's an example using cURL, demonstrating how to retrieve IP geolocation information for a specific IP address using your API key:

curl "https://api.myip.com/info?ip=8.8.8.8&key=YOUR_API_KEY"

In this example:

  • https://api.myip.com/info is the API endpoint for IP information.
  • ip=8.8.8.8 is the query parameter specifying the IP address to look up.
  • key=YOUR_API_KEY is where you replace YOUR_API_KEY with the actual API key obtained from your MY IP dashboard.

The API will return a JSON object containing details such as country, city, and other relevant geolocation data for the specified IP address, provided your API key is valid and your account has sufficient request credits. For a comprehensive list of endpoints and their expected responses, consult the MY IP API reference.

Security best practices

Protecting your MY IP API key is essential to prevent unauthorized access to your account and potential service disruptions. Adhering to these security best practices can mitigate common risks:

  • Keep API Keys Confidential: Never hardcode API keys directly into client-side code (e.g., JavaScript in web pages) or commit them to version control systems like Git. If client-side access is unavoidable, consider using a proxy server to append the key securely.
  • Use Environment Variables: For server-side applications, store your API key as an environment variable rather than directly in your application code. This prevents the key from being exposed if your code repository is compromised.
  • Implement HTTPS: Always make requests over HTTPS. This encrypts the communication between your application and the MY IP API, protecting your API key and other data from interception during transit. The Mozilla Developer Network provides an explanation of HTTPS and its role in secure communication.
  • IP Whitelisting: If MY IP offers IP whitelisting capabilities, use them. This feature restricts API key usage to a predefined list of IP addresses, meaning requests originating from any other IP address will be rejected, even if they have the correct key.
  • Rotate API Keys Regularly: Periodically change your API keys, especially if you suspect a compromise or as part of a routine security policy. MY IP's dashboard should provide functionality to regenerate keys.
  • Monitor Usage: Regularly check your API usage statistics in the MY IP dashboard. Unusual spikes in requests could indicate unauthorized use of your API key.
  • Error Handling: Implement robust error handling in your application. If an API request fails due to an authentication error, log the event (without exposing the key) and investigate.
  • Principle of Least Privilege: If MY IP were to offer different types of API keys with varying permissions (which is not currently indicated for MY IP's simple API), always use the key with the minimum necessary privileges for a given task.

By following these guidelines, you can significantly enhance the security posture of your applications interacting with the MY IP API, protecting both your data and your service access.