summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-08-05 17:22:47 +0300
committerLars Wirzenius <liw@liw.fi>2018-08-05 17:22:47 +0300
commit373f3f95d063e9695f5eeada10da64c0564efa5f (patch)
tree8012a26874808e82c6545bbdeeafd94737dd0e68
parentc8c2bf02508112b110f0743504e0dd0310a8f4d8 (diff)
downloadickweb-373f3f95d063e9695f5eeada10da64c0564efa5f.tar.gz
Fix: getting token
-rw-r--r--ickweb/app.py26
-rwxr-xr-xrun9
2 files changed, 23 insertions, 12 deletions
diff --git a/ickweb/app.py b/ickweb/app.py
index dda2928..d8a79ae 100644
--- a/ickweb/app.py
+++ b/ickweb/app.py
@@ -1,4 +1,6 @@
import json
+import logging
+import logging.handlers
import urllib
import bottle
@@ -10,6 +12,9 @@ client_id = 'ickweb'
COOKIE = 'ickweb-session'
+handler = logging.handlers.SysLogHandler()
+logging.basicConfig(handlers=[handler])
+
def create_app(our_url, controller, client_secret):
app = bottle.Bottle()
api = API(controller)
@@ -71,7 +76,7 @@ def create_app(our_url, controller, client_secret):
headers = {
'Location': url,
}
- print('/login: redirect to', url)
+ print('params:', params)
return bottle.HTTPResponse(status=302, headers=headers)
@app.route('/web/projects')
@@ -100,21 +105,24 @@ def create_app(our_url, controller, client_secret):
@app.route('/web/callback')
def callback():
- print('/callback called')
+ logging.debug('/callback called')
code = bottle.request.query['code']
- print('code:', repr(code))
- token_url = '{}/token'.format(controller)
+ print('code:', code)
+
+ path = '/token'
params = {
'grant_type': 'authorization_code',
'code': code,
}
auth = (client_id, client_secret)
- print('requesting token')
- r = api.POST(token_url, params, auth)
- print('r:', repr(r))
+
+ print('requesting token using code')
+ r = api.POST(path, params, auth)
+
obj = r.json()
token = obj['access_token']
- print('token:', token)
+ print('got access token:', token)
+
bottle.response.set_cookie(COOKIE, token)
bottle.redirect('/web')
@@ -149,6 +157,7 @@ class API:
def POST(self, path, params, auth):
url = self.url(path)
+ print('POST: url:', url)
headers = {}
token = self.get_token()
if token is not None:
@@ -171,7 +180,6 @@ class API:
def get_project(self, name):
url = self.url('/projects', name)
- print('get_project: url:', url)
headers = {
'Authorization': 'Bearer {}'.format(self.get_token())
}
diff --git a/run b/run
index c252f99..2442b0f 100755
--- a/run
+++ b/run
@@ -6,11 +6,14 @@ import ickweb
controller = sys.argv[1]
client_secret_filename = sys.argv[2]
-port = int(sys.argv[3])
-
with open(client_secret_filename) as f:
client_secret = f.readline().strip()
-our_url = '{}/web'.format(controller)
+port = int(sys.argv[3])
+if sys.argv[4] == 'debug':
+ our_url = 'http://localhost:{}/web'.format(port)
+else:
+ our_url = '{}/web'.format(controller)
+
app = ickweb.create_app(our_url, controller, client_secret)
app.run(host='localhost', port=port)