Using Twitcher Client


In [ ]:
# disable ssl warnings
import urllib3
urllib3.disable_warnings()

In [ ]:
from twitcher.client import TwitcherService
base_url = 'http://localhost:8000'
twitcher = TwitcherService(base_url, username='demo', password='demo', verify=False)

Register Client APP


In [ ]:
client = twitcher.add_client_app(name='test1', redirect_uri='http://demo/test1')
client

Register WPS service in Twitcher OWS Proxy


In [ ]:
service = twitcher.register_service(name="emu_demo", url="http://localhost:5000/wps")
service

WPS GetCapabilities request


In [ ]:
import requests

url = "{}/ows/proxy/emu_demo?service=WPS&request=GetCapabilities".format(base_url)
url

In [ ]:
resp = requests.get(url, verify=False)
resp.ok

WPS DescribeProcess request


In [ ]:
url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=DescribeProcess&identifier=hello".format(base_url)
url

In [ ]:
resp = requests.get(url, verify=False)
resp.ok

WPS Execute request ... restricted access


In [ ]:
url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux".format(base_url)
url

In [ ]:
resp = requests.get(url, verify=False)
resp.ok

Access forbidden without access token.


In [ ]:
'AccessForbidden' in resp.text

Get Access token for compute


In [ ]:
compute_token = twitcher.fetch_token(client_id=client['client_id'], client_secret=client['client_secret'], scope='compute')
compute_token

Add access token to parameters


In [ ]:
url = "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux&access_token={}".format(
        base_url, compute_token['access_token'])
url

In [ ]:
resp = requests.get(url, verify=False)
resp.ok

In [ ]:
'Hello Tux' in resp.text

... or add access token to headers


In [ ]:
headers = {'Authorization': 'Bearer {}'.format(compute_token['access_token'])}
headers

In [ ]:
resp = requests.get(
    "{}/ows/proxy/emu_demo?service=WPS&version=1.0.0&request=Execute&identifier=hello&DataInputs=name=Tux".format(base_url),
    headers=headers,
    verify=False)

In [ ]:
'Hello Tux' in resp.text