neo4j-graphacademy / app-python

https://graphacademy.neo4j.com/courses/app-python
56 stars 92 forks source link

Fetching current_user failure and and a possible solution #25

Open pknag opened 6 months ago

pknag commented 6 months ago

In number of methods in the code current_user is fetched like this:

user_id = current_user["sub"] if current_user != None else None

If a user is logged this fails with error:

line 96, in get_current_user raise RuntimeError( RuntimeError: You must provide a@jwt.user_lookup_loadercallback to use this method

My solution is to add the callback method in api/__init__.py right after JWTManager is initialized like this:

jwt = JWTManager(app)

@jwt.user_lookup_loader
def user_lookup_callback(_jwt_header, jwt_data):
    return jwt_data

I am using python==3.11, Flask==2.2.2, Flask-JWT-Extended==4.4.4 as per requirements.txt.