#!/usr/bin/python """ Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import requests import json server='http://localhost:8080' client_id = 'testclient' client_secret = 'testpass' r = requests.post("{}/oauth".format(server), auth=('testclient', 'testpass'), data={'grant_type': 'client_credentials'}) print(r.status_code, r.reason) response = r.json() print("Recieved access token {} of type {}".format(response['access_token'], response['token_type'])) header_auth = {'Authorization': '{} {}'.format(response['token_type'], response['access_token'])} r = requests.post("{}/oauth/resource".format(server), headers=header_auth) print(r.status_code, r.reason) print(r.json()) headers = header_auth headers['Accept'] = 'application/json' headers['Content-Type'] = 'application/json' r = requests.post("{}/waters".format(server), headers=headers, data=json.dumps({'label': 'Forggensee'})) print(r.status_code, r.reason) print(r.json())