Skip to content

Instantly share code, notes, and snippets.

@willrayeo
Created June 5, 2023 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willrayeo/36491fe5c04cf5f523431327d26279e7 to your computer and use it in GitHub Desktop.
Save willrayeo/36491fe5c04cf5f523431327d26279e7 to your computer and use it in GitHub Desktop.
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