I've set up a minimal flask app to test jwt. My authenticate handler works fine, but my identity handler keeps raising TypeError: 'User' object is not callable
app.py
from flask import Flask, current_app
from flask_sqlalchemy import SQLAlchemy
from flask_jwt import JWT, jwt_required, current_identity
from werkzeug.security import safe_str_cmp
app = Flask(__name__)
app.config.from_object('config')
DB = SQLAlchemy(app)
from app.jwt import authenticate, identity # Must import these after the database connection is made
jwt = JWT(app, authenticate, identity)
@app.route('/protected')
@jwt_required()
def protected():
return current_identity
jwt.py
from werkzeug.security import safe_str_cmp
from bcrypt import checkpw
from app.database.models import User
def authenticate(username, password):
user = User.query.filter(User.email == username).scalar()
if user and checkpw(password.encode('utf-8'), user.password.encode('utf-8')):
return user
def identity(payload):
return User.query.filter(User.id == payload['identity']).scalar()
I've set up a minimal flask app to test jwt. My authenticate handler works fine, but my identity handler keeps raising
TypeError: 'User' object is not callable
app.py
jwt.py