Refactor the actual JWT calls into separate functions since I'll be needing them for tokens as well as auth codes

This commit is contained in:
Danielle McLean 2017-11-03 14:37:39 +11:00
parent 6f6bb4e534
commit 40810d6310
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
1 changed files with 10 additions and 2 deletions

View File

@ -4,6 +4,14 @@ from datetime import datetime, timedelta
from django.conf import settings
def encode(payload):
return jwt.encode(payload, settings.SECRET_KEY, algorithm='HS256')
def decode(token):
return jwt.decode(token, settings.SECRET_KEY, algorithms=('HS256',))
def gen_auth_code(post):
params = {'me': post['me']}
if 'state' in post:
@ -20,9 +28,9 @@ def gen_auth_code(post):
if 'scope' in post:
code['sco'] = ' '.join(post.getlist('scope'))
params['code'] = jwt.encode(code, settings.SECRET_KEY, algorithm='HS256')
params['code'] = encode(code)
return params
def verify_auth_code(c):
return jwt.decode(c, settings.SECRET_KEY, algorithms=('HS256',))
return decode(c)