-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@jwt_required does not work with the OPTIONS method #475
Comments
This is happening because in most cases, If this is a use case you need to support, I would be more then happy to have an |
Hi @vimalloc, thanks for your reply. It is not a use case I need to support; this error is raised in our prod app a few times a week, and I was confused by the message trying to trace it. I am not sure why some clients send an OPTIONS request here, as there is no cross-origin situation in our app. Here is how the app is set up, you can see that the error is raised before any Flask route is entered, and therefore before any check on the HTTP method is done. @jwt_required(optional=True)
def get_user_id():
return get_jwt_identity()
@app.before_request
def before_request():
g.user_id = get_user_id()
@app.errorhandler(jwt.exceptions.PyJWTError)
@app.errorhandler(flask_jwt_extended.exceptions.JWTExtendedException)
def handle_expired_token(error):
# Exceptions raised by @jwt_required(optional=True)
logging.warning("Invalid JWT token", exc_info=True)
unset_jwt_cookies(resp)
return unauthorized() I would have expected Otherwise, I can check in my code if the method is OPTIONS, and force Thanks! |
Sorry for the late reply!
It would be, except that the entire callback chain is short circuited if it is an We could update that to not short circuit if |
Hey! Thanks for your reply.
That's the behavior I would expect from the decorator, though I agree it's quite an edge case. So, if it's an easy fix, then why not. ;) For the record, I've added a condition in my code to not attempt to call |
Hello,
Thanks for the great work !
With the OPTIONS HTTP method, a confusing error message is raised, stating that @jwt_required() was not called, although it was called:
Here is a way to reproduce the issue :
The text was updated successfully, but these errors were encountered: