Skip to content

Commit

Permalink
feat: removed flask-jwt unnecesary decorators
Browse files Browse the repository at this point in the history
Flask-JWT specific decorators were removed and replaced by callback functions for Flask-JWT-Extended
  • Loading branch information
alessandrojcm committed Jul 14, 2018
1 parent 805e359 commit 0be659a
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions conduit/utils.py
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

0 comments on commit 0be659a

Please sign in to comment.