summaryrefslogtreecommitdiff
path: root/ickweb
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 /ickweb
parentc8c2bf02508112b110f0743504e0dd0310a8f4d8 (diff)
downloadickweb-373f3f95d063e9695f5eeada10da64c0564efa5f.tar.gz
Fix: getting token
Diffstat (limited to 'ickweb')
-rw-r--r--ickweb/app.py26
1 files changed, 17 insertions, 9 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())
}