Created
June 5, 2023 13:37
-
-
Save willrayeo/36491fe5c04cf5f523431327d26279e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
def get_keycloak(username: str, password: str) -> str: | |
data = { | |
"client_id": "cdse-public", | |
"username": username, | |
"password": password, | |
"grant_type": "password", | |
} | |
try: | |
r = requests.post("https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token", | |
data=data, | |
) | |
r.raise_for_status() | |
except Exception as e: | |
raise Exception( | |
f"Keycloak token creation failed. Reponse from the server was: {r.json()}" | |
) | |
return r.json()["access_token"] | |
keycloak_token = get_keycloak("USERNAME", "PASSWORD") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment