In order to download a product using EOFinder API you have to pass authorisation process by generating and providing keycloak token.
You can obtain it using curl or python itself.
CURL:
123456 | export KEYCLOAK_TOKEN=$(curl -d 'client_id=CLOUDFERRO_PUBLIC' \ -d "username=${OS_USERNAME}" \ -d "password=${OS_PASSWORD}" \ -d 'grant_type=password' \ 'https://auth.creodias.eu/auth/realms/DIAS/protocol/openid-connect/token' | \ python -m json.tool | grep "access_token" | awk -F\" '{print $4}') |
OS_USERNAME and OS_PASSWORD as environmental variables, which were provided after sourcing RC File. (You can download it in Horizon dashboard)
Python:
123456789101112131415161718 | import requests import json
def get_keycloak_token(): h = { 'Content-Type': 'application/x-www-form-urlencoded' } d = { 'client_id': 'CLOUDFERRO_PUBLIC', 'password': 'YOUR_PASSWORD', 'username': 'YOUR_USERNAME', 'grant_type': 'password' } resp = requests.post('https://auth.creodias.eu/auth/realms/dias/protocol/openid-connect/token', data=d, headers=h) return json.loads(resp.content.decode('utf-8'))['access_token']
if __name__ == "__main__": print (get_keycloak_token()) |
Remember, that the token lifespan is set on 600 seconds. You'll have to include a refreshing method if you plan to download a lot of product in the same time.
In this thread you can examine how to add token to the URL properly.
https://creodias.eu/-/how-to-download-eodata-products-using-eofinder-api-
If you need more specific tips, we are ready to deliver an aid.
Regards,
Mateusz