Authentication
Authentication Methods
Access to Hydrosat's STAC API requires basic authentication with valid credentials (username and password).
Basic Authentication
Basic authentication is a simple way to prove your identity when making requests to the STAC API. It works by sending your username and password along with each request. Specifically, the request includes an “Authorization” header that looks like this:
Authorization: Basic <credentials>The <credentials> part is your username and password joined by a colon (like username:password) but encoded in a format called base64. Most tools or libraries that connect to the STAC API will handle the encoding for you, so all you have to do is specify your username and password. Our examples below show this works in practice.
Unauthenticated Requests
Unauthenticated requests to the STAC API will return an error (401 Unauthorized Error).
Examples
The examples below assume that the user has stored their credentials in a separate file called creds.json with the following structure:
{
"username":"your_username",
"password":"your_password"
}For security, we suggest setting credential file permissions to 600 (chmod 600 creds.json) so that only the owner has read and write access.
Of course, there are many other valid approaches for storing and accessing your credentials. If applicable, please consult with your organization's security team to ensure you are complying with preferred methods.
pystac-client
import pystac
from pystac_client import Client
import base64
import json
# Retrieve credentials from file
with open('creds.json') as f:
creds = json.loads(f.read())
userpass = f"{creds['username']}:{creds['password']}" # colon-separated string containing your username and password
b64 = base64.b64encode(userpass.encode()).decode()
headers = {'Authorization':'Basic ' + b64}
catalog = Client.open('https://stac.hydrosat.com/', headers)requests
import requests
import json
# Retrieve credentials from file
with open('creds.json') as f:
creds = json.loads(f.read())
r = requests.get('https://stac.hydrosat.com/collections', auth=(creds['username'], creds['password']))For lengthier examples and next steps, please see our how-to guides.
Last updated
Was this helpful?