source: src/webapp/apigility-testing/test-authorization@ cb39a77

debian/bullseye
Last change on this file since cb39a77 was 74c3571, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago

Added gnuboat_mapservice:

it is a REST webservice designed with Apigility to allow the user to upload data, create waters and so on

  • Property mode set to 100755
File size: 1.6 KB
RevLine 
[74c3571]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
19import requests
20import json
21
22server='http://localhost:8080'
23client_id = 'testclient'
24client_secret = 'testpass'
25
26r = requests.post("{}/oauth".format(server), auth=('testclient', 'testpass'), data={'grant_type': 'client_credentials'})
27print(r.status_code, r.reason)
28response = r.json()
29print("Recieved access token {} of type {}".format(response['access_token'], response['token_type']))
30
31header_auth = {'Authorization': '{} {}'.format(response['token_type'], response['access_token'])}
32r = requests.post("{}/oauth/resource".format(server), headers=header_auth)
33print(r.status_code, r.reason)
34print(r.json())
35
36headers = header_auth
37headers['Accept'] = 'application/json'
38headers['Content-Type'] = 'application/json'
39r = requests.post("{}/waters".format(server), headers=headers, data=json.dumps({'label': 'Forggensee'}))
40print(r.status_code, r.reason)
41print(r.json())
Note: See TracBrowser for help on using the repository browser.