RRAP-IS Authentication Demo Notebook
A tutorial of RRAP authentication using Jupyter notebooks.
import requests
import os
import sys
import json
from IPython.core.display import display, HTML
from IPython.display import IFrame
from mdsisclienttools.auth.TokenManager import DeviceFlowManager
data_api = "https://data-api.testing.rrap-is.com"
registry_api = "https://registry-api.testing.rrap-is.com"
prov_api = "https://prov-api.testing.rrap-is.com"
auth_server = "https://auth.dev.rrap-is.com/auth/realms/rrap"
# garbage = "https://frogs.are.green"
base_urls = {'data_api': data_api, 'registry_api': registry_api, 'prov_api': prov_api, 'auth_server': auth_server}#, 'garbage': garbage}
display(f'Checking base urls')
for key, url in base_urls.items():
try:
print(f'Testing - {url}', end="")
r = requests.get(url)
r.raise_for_status()
print(f' - Passed')
except requests.exceptions.HTTPError as err:
print(f' - Fail')
raise SystemExit(err)
except requests.exceptions.RequestException as e:
# catastrophic error. bail.
print(f' - Fail')
raise SystemExit(e)
local_token_storage = ".tokens.json"
token_manager = DeviceFlowManager(
stage="TEST",
keycloak_endpoint=auth_server,
local_storage_location=local_token_storage
)
Endpoint Documentation
Endpoint documentation can be found by appending either /docs or /redoc on the end a base URL.
For example:
Then select from the menu an endpoint function call e.g. /check-access/check-general-access
Then append the function call onto the base url e.g. https://registry-api.testing.rrap-is.com/check-access/check-general-access
auth = token_manager.get_auth
base_url = "https://registry-api.testing.rrap-is.com"
url_query_string = "/check-access/check-general-access"
endpoint = base_url + url_query_string
response = requests.get(endpoint, auth=auth())
print(json.dumps(response.json(), indent=4, sort_keys=True))
auth = token_manager.get_auth
base_url = "https://registry-api.testing.rrap-is.com"
url_query_string = "/check-access/check-read-access"
endpoint = base_url + url_query_string
response = requests.get(endpoint, auth=auth())
print(json.dumps(response.json(), indent=4, sort_keys=True))
auth = token_manager.get_auth
base_url = "https://registry-api.testing.rrap-is.com"
url_query_string = "/check-access/check-write-access"
endpoint = base_url + url_query_string
response = requests.get(endpoint, auth=auth())
print(json.dumps(response.json(), indent=4, sort_keys=True))
auth = token_manager.get_auth
base_url = "https://registry-api.testing.rrap-is.com"
url_query_string = "/check-access/check-admin-access"
endpoint = base_url + url_query_string
response = requests.get(endpoint, auth=auth())
print(json.dumps(response.json(), indent=4, sort_keys=True))