#!/usr/bin/env python # coding: utf-8 # ### Execute WPS request without token # In[ ]: 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 # In[ ]: import requests # In[ ]: resp = requests.get(url) resp.ok # In[ ]: 'AccessForbidden' in resp.text # ### Execute WPS request with token # Get a token from keycloak via phoenix client: # https://demo-phoenix.cloud.dkrz.de # In[ ]: access_token = '' # In[ ]: headers = {'Authorization': 'Bearer {}'.format(access_token)} # In[ ]: resp = requests.get(url, headers=headers) resp.ok # In[ ]: 'ProcessSucceeded' in resp.text # In[ ]: 'Hello Stranger' in resp.text # ### Use Birdy # In[ ]: from birdy import WPSClient emu = WPSClient(url=base_url, headers=headers) # In[ ]: response = emu.hello(name='Stranger') # In[ ]: response.get() # ### Keycloak client # In[ ]: 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 = '' # ### Get OAuth access token from Keycloak # In[ ]: token_url = "{}{}".format(keycloak_url, token_endpoint) token_url # In[ ]: 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 # In[ ]: token['access_token'] # ### Run request with birdy # In[ ]: from birdy import WPSClient headers = {'Authorization': 'Bearer {}'.format(token['access_token'])} emu = WPSClient(url=base_url, headers=headers) # In[ ]: response = emu.hello(name='Stranger') # In[ ]: response.get()