summaryrefslogtreecommitdiff
path: root/yarns
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-05 12:48:47 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-05 12:48:47 +0100
commit3828e97529d0d606a5b3074442ec02ae3c22193a (patch)
tree59d3fc23b9d5d72425eaa5a82075faa15ca167ea /yarns
parente213b794bfa6bc04679e0c99b3f495995b6c0520 (diff)
downloadick2-3828e97529d0d606a5b3074442ec02ae3c22193a.tar.gz
Add: add helpers for storing, retrieving tokens for users
Diffstat (limited to 'yarns')
-rw-r--r--yarns/lib.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/yarns/lib.py b/yarns/lib.py
index 0b95a81..b508389 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -75,12 +75,22 @@ def cat(filename):
return open(filename, 'r').read()
+def store_token(user, token):
+ filename = '{}.jwt'.format(user)
+ write(filename, token)
+
+
+def get_token(user):
+ filename = '{}.jwt'.format(user)
+ return cat(filename)
+
+
def get(url, token):
headers = {
'Authorization': 'Bearer {}'.format(token),
}
r = requests.get(url, headers=headers, verify=False)
- return r.status_code, r.headers['Content-Type'], r.text
+ return r.status_code, r.headers['Content-Type'], dict(r.headers), r.text
def post(url, body_text, token):