Authentication overview
The Global Biodiversity Information Facility (GBIF) provides open access to biodiversity data through its API. For the majority of data retrieval operations, such as searching occurrence records or datasets, no authentication is required. This design facilitates broad accessibility for researchers, developers, and the public to use biodiversity data without needing to manage API keys or user sessions GBIF developer summary page. However, certain API endpoints that involve user-specific actions, such as managing registered datasets, accessing user profiles, or interacting with the GBIF publishing platform, require authentication. These authenticated endpoints typically use HTTP Basic Authentication.
Developers interacting with GBIF's API should differentiate between public endpoints and those requiring user context. Public endpoints allow for anonymous requests, making it straightforward to integrate GBIF data into applications without any setup. For operations that modify or access private user data, a registered GBIF user account is necessary to generate the required credentials. All interactions with the GBIF API, whether authenticated or not, should occur over HTTPS to ensure data integrity and confidentiality during transmission GBIF API documentation.
Supported authentication methods
GBIF primarily utilizes HTTP Basic Authentication for endpoints that require user verification. This method involves sending a username and password with each API request, typically encoded in a base64 string within the Authorization header. While straightforward to implement, it necessitates careful handling of credentials to prevent exposure. Other common authentication mechanisms, such as OAuth 2.0 or API keys, are not the primary method for most GBIF API interactions, reinforcing the platform's focus on open data access for its core services.
The choice of HTTP Basic Authentication aligns with the need for a simple, widely supported mechanism for user-specific actions within a system that otherwise prioritizes unauthenticated public access. Developers should be aware of the security implications of HTTP Basic Authentication and ensure their applications handle credentials securely, especially when operating in client-side environments or public networks. For a general understanding of HTTP Basic Authentication, consult the MDN Web Docs on HTTP Authentication.
Authentication methods table
| Method | When to Use | Security Level |
|---|---|---|
| No Authentication | Accessing public data (e.g., occurrence searches, dataset metadata) | Public (no user-specific data) |
| HTTP Basic Authentication | User-specific actions (e.g., managing registered datasets, accessing user profile information, publishing data) | Standard (requires secure credential management) |
Getting your credentials
To obtain the necessary credentials for authenticated GBIF API endpoints, you must first register for a user account on the GBIF website. The registration process typically involves providing an email address, creating a username, and setting a password. This account serves as your identity for both the web portal and API interactions requiring authentication.
- Create a GBIF Account: Navigate to the GBIF user registration page and follow the prompts to create a new account. You will need to verify your email address.
- Use Username and Password: Once your account is active, your chosen username and password will serve as the credentials for HTTP Basic Authentication. There is no separate API key or token generation process for this method.
- Keep Credentials Secure: Treat your GBIF username and password with the same security precautions as other sensitive login information. Do not embed them directly into client-side code or public repositories.
It is important to remember that these credentials grant access to your user-specific data and capabilities within the GBIF ecosystem. For applications, consider using environment variables or secure configuration files to store and access these credentials, rather than hardcoding them.
Authenticated request example
This example demonstrates how to make an authenticated request using HTTP Basic Authentication with Python's requests library. For this example, we'll assume an endpoint that requires authentication, such as one related to user-specific dataset management, though specific authenticated endpoints may vary. Replace YOUR_GBIF_USERNAME and YOUR_GBIF_PASSWORD with your actual GBIF account credentials.
import requests
from requests.auth import HTTPBasicAuth
# Replace with your actual GBIF username and password
username = "YOUR_GBIF_USERNAME"
password = "YOUR_GBIF_PASSWORD"
# Example authenticated endpoint (replace with a real authenticated endpoint if available)
# Note: Most GBIF endpoints are public. This is illustrative for authentication.
authenticated_endpoint = "https://api.gbif.org/v1/user/me" # Example: get current user info
try:
# Make the GET request with basic authentication
response = requests.get(authenticated_endpoint, auth=HTTPBasicAuth(username, password))
# Check if the request was successful (status code 200)
if response.status_code == 200:
print("Successfully authenticated and retrieved data:")
print(response.json()) # Print the JSON response
elif response.status_code == 401:
print("Authentication failed: Invalid credentials.")
print(f"Response: {response.text}")
else:
print(f"Request failed with status code {response.status_code}")
print(f"Response: {response.text}")
except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
In this Python snippet, the HTTPBasicAuth object from the requests library handles the base64 encoding and inclusion of the Authorization header automatically. For other programming languages, the pattern remains similar: construct the Authorization header with Basic base64(username:password) and include it in your HTTP request. Always ensure your requests are sent over HTTPS to protect your credentials during transit.
Security best practices
When working with GBIF's authenticated API endpoints, adherence to security best practices is crucial to protect your credentials and maintain the integrity of your applications. While GBIF primarily uses HTTP Basic Authentication, which is simple, it places a greater responsibility on the developer for secure handling.
- Always Use HTTPS: Ensure all API requests, especially authenticated ones, are made over HTTPS. This encrypts the communication channel, preventing eavesdropping and protecting your username and password from being intercepted in plain text GBIF developer documentation.
- Secure Credential Storage: Never hardcode your GBIF username and password directly into your application's source code, especially for client-side applications or public repositories. Instead, use environment variables, secure configuration files, or a secrets management service (e.g., AWS Secrets Manager, Google Secret Manager) to store and retrieve credentials at runtime.
- Limit Credential Scope: Only use credentials in environments and applications where they are strictly necessary. If possible, avoid sharing credentials across multiple applications or services.
- Error Handling: Implement robust error handling for authentication failures. Avoid exposing sensitive information in error messages that might be visible to end-users or logs. Generic messages like "Authentication failed" are preferable.
- Regular Credential Rotation: While not strictly enforced by GBIF, periodically changing your GBIF account password is a good general security practice to mitigate risks associated with potential credential compromise.
- Principle of Least Privilege: If GBIF were to offer more granular access controls in the future (e.g., specific scopes), always request or use only the minimum permissions necessary for your application's function.
- Monitor for Suspicious Activity: Keep an eye on the activity associated with your GBIF account, especially if you are using it for automated API interactions. Report any unusual behavior to GBIF support immediately.
By following these guidelines, developers can minimize security risks and ensure responsible use of the GBIF API, protecting both their applications and the broader GBIF ecosystem.