Thanks for taking a look. I am trying to implement Flask-JWT-Ext. I have redis blacklist implemented in order to revoke my tokens.
I am trying to use get_current_user(), get_jwt_identity() etc but it is returning None, despite passing in the access tokens on with @jwt_required decorator...
Here is my login (which correctly generates access and refresh tokens):
@app.route('/login', methods=['POST'])
def check_login_info():
'''
Login user
'''
arw = ApiResponseWrapper()
login_data = request.get_json()
try:
matching_login = Login.query.filter_by(username=login_data['username']).one()
matching_login.check_password(login_data['password_hash'])
access_token = create_access_token(identity=matching_login.username)
access_jti = get_jti(encoded_token=access_token)
revoked_store.set(access_jti, 'false', timedelta(minutes=15) * 1.2)
refresh_token = create_refresh_token(identity=matching_login.username)
refresh_jti = get_jti(encoded_token=refresh_token)
revoked_store.set(refresh_jti, 'false', timedelta(days=30) * 1.2)
tokens = {
'access_token': access_token,
'refresh_token': refresh_token
}
except (MultipleResultsFound, NoResultFound):
arw.add_errors('No result found or multiple results found')
except ValueError:
arw.add_errors('Value error')
except BadRequestsError:
arw.add_errors('Bad requests error')
if arw.has_errors():
return arw.to_json(None, 400)
return jsonify(tokens), 201
I wasn't able to use get_current_user(), etc on a different route, so I made a sample one to test it out. It returns None for current user and identity, despite passing in the correct tokens in the header.
@jwt_required
@app.route('/check', methods=['GET'])
def check_login():
current_user = get_current_user()
user_has_tokens = get_jwt_identity()
return jsonify({"user": current_user, "tokens": user_has_tokens}), 201
Do you know what I'm missing? I definitely have the redis blacklist set up correctly and generating tokens with create_access_token, etc work.
Thanks