| 1 | #!/usr/bin/python
|
|---|
| 2 | """
|
|---|
| 3 | Copyright (C) 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | """
|
|---|
| 18 |
|
|---|
| 19 | import requests
|
|---|
| 20 | import json
|
|---|
| 21 |
|
|---|
| 22 | server='http://localhost:8080'
|
|---|
| 23 | client_id = 'testclient'
|
|---|
| 24 | client_secret = 'testpass'
|
|---|
| 25 |
|
|---|
| 26 | r = requests.post("{}/oauth".format(server), auth=('testclient', 'testpass'), data={'grant_type': 'client_credentials'})
|
|---|
| 27 | print(r.status_code, r.reason)
|
|---|
| 28 | response = r.json()
|
|---|
| 29 | print("Recieved access token {} of type {}".format(response['access_token'], response['token_type']))
|
|---|
| 30 |
|
|---|
| 31 | header_auth = {'Authorization': '{} {}'.format(response['token_type'], response['access_token'])}
|
|---|
| 32 | r = requests.post("{}/oauth/resource".format(server), headers=header_auth)
|
|---|
| 33 | print(r.status_code, r.reason)
|
|---|
| 34 | print(r.json())
|
|---|
| 35 |
|
|---|
| 36 | headers = header_auth
|
|---|
| 37 | headers['Accept'] = 'application/json'
|
|---|
| 38 | headers['Content-Type'] = 'application/json'
|
|---|
| 39 | r = requests.post("{}/waters".format(server), headers=headers, data=json.dumps({'label': 'Forggensee'}))
|
|---|
| 40 | print(r.status_code, r.reason)
|
|---|
| 41 | print(r.json())
|
|---|