-
-
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.expired_token_loader decorator not trigerring callback function to catch ExpiredSignatureError('Signature has expired') #83
Comments
I found a workaround to use the flask-restplus errorhandler as indicated on http://flask-restplus.readthedocs.io/en/stable/errors.html. But shouldn't the callback function work 'catching' the error? |
From what I can tell, the problem stems from flask-restplus trying to implement it's own error handlers in an I'm not sure why they went that route, but there isn't much I can do about it in my extension. Breaking native flask functionality does not make for an extension that plays nice with others. I pinged them about this issue, and if they get back to me with how it could be resolved I'll make sure to update this. In the mean time, the only things I could think to do would be to either:
|
I am adding this here as well as #86 for completeness sake. I've thought of a better way to solve this. It is very much a hack, and I still think flask-restplus should fix their extension so that it does not break native flask features, but it should get you up and going safer then how you have it handled above. It looks like the errorhandler method for restplus uses the same signature that flask error handler does, so you could take advantage of duck typing and access this internal method to set the errors on the restplus level: https://github.com/vimalloc/flask-jwt-extended/blob/master/flask_jwt_extended/jwt_manager.py#L81 from flask import Flask
from flask_jwt_extended import JWTManager
from flask_restplus import Api
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = 'super-secret' # Change this!
jwt = JWTManager(app)
api = Api()
# This is where the duck typing magic comes in
jwt._set_error_handler_callbacks(api) This would obviously be prone to break if I changed how the underlying part of this extension worked, as you are accessing a private method that doesn't have any guarantees on it, but I do not see any reason why that method would change in the foreseeable future, and this would insure that any new or changed error handles in this extension would get properly set on the flask-restplus extension. Hope this helps :) |
I'm going to close this issue. Future discussions of it will continue in #86 |
I'm using flask-restplus framework with blueprints and namespaces.
I copy-pasted the code from the tutorial/documentation seen on http://flask-jwt-extended.readthedocs.io/en/latest/changing_default_behavior.html
as the image below show
But it always rise the error instead of triggering the callback function, as the log indicates
is it because my flask aplication doesn't have @app.route('/') and instead uses @flask-resplus.namespace.route('/') ? How can i achieve the desired result?
The text was updated successfully, but these errors were encountered: