<jupyter_start><jupyter_text>Execute WPS request without token<jupyter_code>base_url = 'http://demo-twitcher.cloud.dkrz.de/ows/proxy/emu'
url = "{}/ows/proxy/emu?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Stranger".format(base_url)
url
import requests
resp = requests.get(url)
resp.ok
'AccessForbidden' in resp.text<jupyter_output><empty_output><jupyter_text>Execute WPS request with token Get a token from keycloak via phoenix client: https://demo-phoenix.cloud.dkrz.de<jupyter_code>access_token = ''
headers = {'Authorization': 'Bearer {}'.format(access_token)}
resp = requests.get(url, headers=headers)
resp.ok
'ProcessSucceeded' in resp.text
'Hello Stranger' in resp.text<jupyter_output><empty_output><jupyter_text>Use Birdy<jupyter_code>from birdy import WPSClient
emu = WPSClient(url=base_url, headers=headers)
response = emu.hello(name='Stranger')
response.get()<jupyter_output><empty_output><jupyter_text>Keycloak client<jupyter_code>keycloak_url = 'https://auth-test.ceda.ac.uk'
token_endpoint = '/auth/realms/master/protocol/openid-connect/token'
client_id = 'demo-1'
# copy secret from demo-1 client
client_secret = ''<jupyter_output><empty_output><jupyter_text>Get OAuth access token from Keycloak<jupyter_code>token_url = "{}{}".format(keycloak_url, token_endpoint)
token_url
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(
    token_url,
    # scope='compute',
    client_id=client_id,
    client_secret=client_secret,
    include_client_id=True,
    verify=True)
token
token['access_token']<jupyter_output><empty_output><jupyter_text>Run request with birdy<jupyter_code>from birdy import WPSClient
headers = {'Authorization': 'Bearer {}'.format(token['access_token'])}
emu = WPSClient(url=base_url, headers=headers)
response = emu.hello(name='Stranger')
response.get()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12462760675273088, 'fraction_numerical': 0.003972194637537239, 'mean_word_length': 8.460093896713616, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '207724', 'license': 'Apache-2.0', 'n_tokens_mistral': 718, 'n_tokens_neox': 713, 'n_words': 114, 'path': 'notebooks/twitcher-keycloak-online-demo.ipynb', 'repo_name': 'bird-house/twitcher', 'size': '2014'}