Authentication overview

Authentication for the Materials Platform for Data Science (MPDS) is primarily managed through API keys. This mechanism allows developers and researchers to programmatically access the platform's extensive database of materials properties and experimental data. Each API key is unique to a user account and is used to identify and authorize requests made to the MPDS API. The platform's API is designed to support data-driven materials discovery and research, providing access to curated information on crystal structures, experimental conditions, and physical properties of various materials.

The use of API keys simplifies the integration process, enabling developers to incorporate MPDS data into their applications, scripts, and research workflows without complex authentication flows. The API keys are tied to specific user accounts and their associated subscription plans, which dictate the allowable rate limits and access levels to different datasets. This tiered access ensures that resources are allocated according to user needs and subscription entitlements, ranging from free tier access with limited calls and data to enterprise-level plans offering comprehensive data access and higher request volumes. For detailed information on API capabilities and data structure, refer to the official MPDS API reference.

Adhering to secure practices in handling API keys is critical to prevent unauthorized access to data and services. MPDS emphasizes the importance of treating API keys as sensitive credentials, similar to passwords. Best practices include storing keys securely, transmitting them over encrypted channels (HTTPS), and rotating them periodically. The platform's approach to authentication is designed to balance ease of use for scientific and engineering applications with robust security measures to protect intellectual property and research data.

Supported authentication methods

The Materials Platform for Data Science primarily supports API key authentication for accessing its data and services. This method is common for web APIs due to its simplicity and effectiveness in managing access to resources. When a user registers for an MPDS account, they can generate API keys directly from their user dashboard. These keys are then included in API requests to verify the user's identity and determine their authorization level based on their subscription plan.

API keys act as a token that grants access to specific functionalities or data within the MPDS platform. They represent a straightforward mechanism for client applications to authenticate with the server. Unlike more complex protocols like OAuth 2.0, which are designed for delegated authorization across multiple services, API keys are typically used for direct application-to-server authentication where the application itself is the primary consumer of the API. For a broader understanding of API key security, consult the Cloudflare API key security guidelines.

The following table outlines the supported authentication method, its typical use cases, and associated security considerations:

Method When to Use Security Level
API Key Programmatic access to MPDS data, scripting, backend integrations, single-application use. Medium (Requires secure key management, HTTPS transmission, and periodic rotation to prevent compromise.)

While API keys offer simplicity, it is crucial to implement them securely. They should never be hardcoded into client-side code, exposed in public repositories, or transmitted over unencrypted connections. MPDS ensures that all API communication occurs over HTTPS, encrypting data in transit and protecting API keys from interception during transmission.

Getting your credentials

To obtain your API key for the Materials Platform for Data Science, you must first register for an account on the MPDS website. Once registered and logged in, you can navigate to your personal dashboard or account settings section, where options for API key management are typically found.

  1. Create an MPDS Account: Visit the MPDS homepage and complete the registration process. This typically involves providing an email address, setting a password, and agreeing to the terms of service.
  2. Log In: Access your account using your newly created credentials.
  3. Navigate to API Key Management: Within your user dashboard, look for sections like "API Settings," "Developer Access," or "My Keys." The exact navigation path may vary but will be clearly indicated.
  4. Generate a New API Key: Most platforms provide an option to generate new API keys. Upon generation, your unique key will be displayed. It is critical to copy this key immediately, as some platforms (including MPDS) might only show it once for security reasons.
  5. Store Your Key Securely: Once copied, store your API key in a secure location. Avoid saving it in plain text files on your local machine or committing it directly into version control systems like Git without proper encryption or environment variable usage.

MPDS offers various subscription tiers, including a free tier with limited API calls and data access. The level of access and the number of API calls you can make will depend on your chosen plan. Different plans may also grant access to specific datasets or advanced functionalities. Your API key will automatically reflect the permissions associated with your current subscription.

If you suspect your API key has been compromised or if you need to revoke access for any reason, you can typically do so from the same API key management section in your dashboard. Generating a new key and updating your applications with the new credential is a recommended security practice following a compromise or as part of a regular key rotation strategy.

Authenticated request example

Accessing the Materials Platform for Data Science API requires including your API key in each request. The MPDS API typically expects the API key to be passed as a query parameter or within a custom HTTP header. The official MPDS documentation provides specific examples for Python, which is a primary language supported by their SDK.

Here's a Python example demonstrating how to make an authenticated request using the requests library, passing the API key as a query parameter. This example assumes you have an API key stored in an environment variable for security.

import os
import requests

# It's best practice to load your API key from environment variables
MPDS_API_KEY = os.environ.get("MPDS_API_KEY")

if not MPDS_API_KEY:
    raise ValueError("MPDS_API_KEY environment variable not set.")

BASE_URL = "https://api.mpds.io/v0/" # Example base URL

# Example endpoint for querying materials data
ENDPOINT = "materials/search"

# Parameters for the query
params = {
    "q": "silicon", # Search query for 'silicon'
    "limit": 5,     # Limit results to 5
    "api_key": MPDS_API_KEY # Include the API key
}

try:
    response = requests.get(f"{BASE_URL}{ENDPOINT}", params=params)
    response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)

    data = response.json()
    print("Successfully retrieved data:")
    for material in data.get("results", [])[:5]: # Print first 5 results for brevity
        print(f"- {material.get('chemical_formula', 'N/A')} (Phase: {material.get('phase_label', 'N/A')})")

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err}")
    print(f"Response content: {response.text}")
except requests.exceptions.ConnectionError as conn_err:
    print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
    print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
    print(f"An unexpected error occurred: {req_err}")

In this example, the api_key parameter directly includes your credential. Always ensure that environment variables are used for sensitive information like API keys, especially in production environments or when sharing code. This prevents the key from being hardcoded into your script and accidentally exposed.

For more complex queries, filtering options, or different data endpoints, consult the official MPDS API documentation, which provides comprehensive details on available parameters and response formats. The Python SDK also abstracts much of this complexity, offering a more idiomatic way to interact with the API.

Security best practices

Securing your API keys for the Materials Platform for Data Science is paramount to protecting your data access and preventing unauthorized usage of your account's quota. Adhering to established security best practices can significantly mitigate risks associated with API key exposure.

  1. Keep API Keys Confidential: Treat your MPDS API key with the same level of confidentiality as you would a password. Never embed API keys directly in client-side code (e.g., JavaScript in a public web page) or commit them to public version control repositories like GitHub.
  2. Use Environment Variables: For server-side applications, scripts, and local development, store API keys in environment variables. This prevents the key from being hardcoded into your application's source code, making it easier to manage and less likely to be exposed. Many programming languages and frameworks offer mechanisms to load environment variables securely.
  3. Restrict Access to Keys: Limit who has access to your API keys. Only authorized personnel or automated systems should be able to retrieve or use them. Implement strict access controls on the systems where keys are stored.
  4. Transmit Keys Securely (HTTPS): Always ensure that all communications with the MPDS API occur over HTTPS (HTTP Secure). HTTPS encrypts the data in transit, protecting your API key and other sensitive information from interception by malicious actors. The MPDS API enforces HTTPS connections by default.
  5. Implement IP Whitelisting (if available): If the MPDS platform offers IP whitelisting, configure your API key to only accept requests from a predefined set of trusted IP addresses. This adds an extra layer of security, as even if your key is stolen, it cannot be used from an unauthorized location.
  6. Rotate API Keys Periodically: Regularly generate new API keys and revoke old ones. This practice, known as key rotation, reduces the window of opportunity for a compromised key to be exploited. The recommended frequency for rotation can vary based on your security policies and risk assessment.
  7. Monitor API Usage: Regularly review your API usage logs and billing statements (if applicable). Unexpected spikes in usage or calls from unfamiliar locations could indicate a compromised key. Prompt investigation can help identify and mitigate security incidents early.
  8. Error Handling and Logging: Implement robust error handling in your applications to manage API request failures gracefully. Avoid logging API keys or other sensitive credentials in application logs, as these logs can sometimes be accessed by unauthorized individuals.
  9. Principle of Least Privilege: If MPDS offers API keys with different permission scopes, generate keys with the minimum necessary permissions required for your application's functionality. This limits the damage that could be done if a key is compromised.

By following these best practices, you can significantly enhance the security posture of your integrations with the Materials Platform for Data Science, ensuring that your research data and API access remain protected. For general API security principles, refer to resources like the Microsoft Azure API security best practices for broader context.