-
-
Notifications
You must be signed in to change notification settings - Fork 389
Added JWT authentication. #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,7 @@ def jwt_authenticator_name(): | |
def json_web_token(request, response, verify_token, jwt_secret): | ||
"""JWT verification | ||
|
||
Checks for the Authorization header and verifies it using the verify_token function | ||
Checks for the Authorization header and verifies it using the verify_token function. | ||
""" | ||
authorization = request.get_header('Authorization') | ||
if authorization: | ||
|
@@ -197,13 +197,9 @@ def verify_jwt(authorization, response, jwt_secret): | |
try: | ||
token = authorization.split(' ')[1] | ||
decoding = jwt.decode(token, jwt_secret, algorithm='HS256') | ||
print(decoding) | ||
return decoding['user_id'] | ||
except Exception as ex: | ||
template = "An exception of type {0} occurred. Arguments:\n{1!r}" | ||
print(template.format(type(ex).__name__, ex.args)) | ||
except: | ||
|
||
return False | ||
return None | ||
|
||
def new_jwt(user_id, token_expiration_seconds, jwt_secret): | ||
return jwt.encode({'user_id': user_id, | ||
|
@@ -220,10 +216,6 @@ def refresh_jwt(authorization, token_refresh_seconds, token_expiration_seconds, | |
return jwt.encode({'user_id': decoding['user_id'], | ||
'exp': datetime.utcnow() + timedelta(seconds=token_expiration_seconds)}, | ||
jwt_secret, algorithm='HS256').decode("utf-8") | ||
else: | ||
return None | ||
except Exception as ex: | ||
template = "An exception of type {0} occurred. Arguments:\n{1!r}" | ||
print(template.format(type(ex).__name__, ex.args)) | ||
except: | ||
|
||
return None | ||
# END - JWT AUTH # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally there will be 2 new lines between function and classes and one new line between class methods. Please add a new line.