TokenHandler is a Python class intended to ease the authentication process within SALTED. It is aimed at partners working on WP2 and WP4 activities, but may also be of use to external users developing DET components.
Install as package in your Python 3 environment:
pip install git+https://github.com/SALTED-Project/TokenHandler.gitfromtokenhandler.handlerimportTokenHandlerimportrequests# instantiate TokenHandlerth=TokenHandler("https://auth.salted-project.eu/realms/SALTED/protocol/openid-connect/token", <yourkeycloakclientID>, <yourkeycloakclientsecret>)
# obtain valid tokentoken=th.get_token()
# test token with scorpio brokerheaders= {
'Authorization' : 'Bearer '+token,
'Accept': 'application/ld+json'
}
r=requests.get("https://context-broker.salted-project.eu/ngsi-ld/v1/entities?type=Organization",headers=headers)
print(r.json())