API - update pyjwt to 2.0.0

jwt.encode() returns now tokens as string instead of a byte string
This commit is contained in:
Sam
2020-12-25 19:35:15 +01:00
parent 26d9402425
commit c890ec6be1
6 changed files with 25 additions and 20 deletions

View File

@ -136,7 +136,7 @@ def register_user():
response_object = {
'status': 'success',
'message': 'Successfully registered.',
'auth_token': auth_token.decode(),
'auth_token': auth_token,
}
return jsonify(response_object), 201
else:
@ -220,7 +220,7 @@ def login_user():
response_object = {
'status': 'success',
'message': 'Successfully logged in.',
'auth_token': auth_token.decode(),
'auth_token': auth_token,
}
return jsonify(response_object), 200
else:
@ -708,7 +708,7 @@ def request_password_reset():
),
'username': user.username,
'password_reset_url': (
f'{ui_url}/password-reset?token={password_reset_token.decode()}' # noqa
f'{ui_url}/password-reset?token={password_reset_token}' # noqa
),
'operating_system': request.user_agent.platform,
'browser_name': request.user_agent.browser,

View File

@ -29,5 +29,9 @@ def get_user_token(user_id, password_reset=False):
def decode_user_token(auth_token):
payload = jwt.decode(auth_token, current_app.config.get('SECRET_KEY'))
payload = jwt.decode(
auth_token,
current_app.config.get('SECRET_KEY'),
algorithms=['HS256'],
)
return payload['sub']