Browse Source

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

pull/1/head
Danielle McLean 4 years ago
parent
commit
40810d6310
Signed by: 00dani GPG Key ID: 5A5D2D1AFF12EEC5
  1. 12
      lemonauth/tokens.py

12
lemonauth/tokens.py

@ -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)

Loading…
Cancel
Save