forked from gothinkster/flask-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed flask-jwt unnecesary decorators
Flask-JWT specific decorators were removed and replaced by callback functions for Flask-JWT-Extended
- Loading branch information
1 parent
805e359
commit 0be659a
Showing
1 changed file
with
4 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Helper utilities and decorators.""" | ||
from flask import flash, _request_ctx_stack | ||
from functools import wraps | ||
from flask_jwt import _jwt | ||
import jwt | ||
|
||
|
||
def jwt_optional(realm=None): | ||
def wrapper(fn): | ||
@wraps(fn) | ||
def decorator(*args, **kwargs): | ||
token = _jwt.request_callback() | ||
try: | ||
payload = _jwt.jwt_decode_callback(token) | ||
except jwt.exceptions.DecodeError: | ||
pass | ||
else: | ||
_request_ctx_stack.top.current_identity = _jwt.identity_callback(payload) | ||
return fn(*args, **kwargs) | ||
return decorator | ||
return wrapper | ||
|
||
|
||
from conduit.user.models import User # noqa | ||
|
||
from conduit.user.models import User # noqa | ||
|
||
def jwt_identity(payload): | ||
user_id = payload['identity'] | ||
return User.get_by_id(user_id) | ||
|
||
return User.get_by_id(payload) | ||
|
||
def authenticate(email, password): | ||
user = User.query.filter_by(email=email).first() | ||
if user and user.check_password(password): | ||
return user | ||
def identity_loader(user): | ||
return user.id |