From 539ee816a0f502d58d26a97a65ff393d198000cb Mon Sep 17 00:00:00 2001 From: Alex Wang Date: Mon, 27 Aug 2018 12:31:06 +0800 Subject: [PATCH] improve document of loader functions more noticeable --- flask_jwt_extended/jwt_manager.py | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/flask_jwt_extended/jwt_manager.py b/flask_jwt_extended/jwt_manager.py index b7407dbe..eb47b836 100644 --- a/flask_jwt_extended/jwt_manager.py +++ b/flask_jwt_extended/jwt_manager.py @@ -200,11 +200,11 @@ def user_claims_loader(self, callback): access token when :func:`~flask_jwt_extended.create_access_token` is called. By default, no extra user claims will be added to the JWT. - The callback function must be a function that takes only one argument, + *HINT*: The callback function must be a function that takes only **one** argument, which is the object passed into :func:`~flask_jwt_extended.create_access_token`, and returns the custom claims you want included in the access tokens. This returned claims - must be JSON serializable. + must be *JSON serializable*. """ self._user_claims_callback = callback return callback @@ -218,11 +218,11 @@ def user_identity_loader(self, callback): return the unmodified object that is passed in as the `identity` kwarg to the above functions. - The callback function must be a function that takes only one argument, + *HINT*: The callback function must be a function that takes only **one** argument, which is the object passed into :func:`~flask_jwt_extended.create_access_token` or :func:`~flask_jwt_extended.create_refresh_token`, and returns the - JSON serializable identity of this token. + *JSON serializable* identity of this token. """ self._user_identity_callback = callback return callback @@ -235,8 +235,8 @@ def expired_token_loader(self, callback): {"msg": "Token has expired"} - The callback must be a function that takes zero arguments, and returns - a Flask response. + *HINT*: The callback must be a function that takes **zero** arguments, and returns + a *Flask response*. """ self._expired_token_callback = callback return callback @@ -249,9 +249,9 @@ def invalid_token_loader(self, callback): {"msg": ""} - The callback must be a function that takes only one argument, which is + *HINT*: The callback must be a function that takes only **one** argument, which is a string which contains the reason why a token is invalid, and returns - a Flask response. + a *Flask response*. """ self._invalid_token_callback = callback return callback @@ -264,9 +264,9 @@ def unauthorized_loader(self, callback): {"msg": ""} - The callback must be a function that takes only one argument, which is + *HINT*: The callback must be a function that takes only **one** argument, which is a string which contains the reason why a JWT could not be found, and - returns a Flask response. + returns a *Flask response*. """ self._unauthorized_callback = callback return callback @@ -280,8 +280,8 @@ def needs_fresh_token_loader(self, callback): {"msg": "Fresh token required"} - The callback must be a function that takes no arguments, and returns - a Flask response. + *HINT*: The callback must be a function that takes **no** arguments, and returns + a *Flask response*. """ self._needs_fresh_token_callback = callback return callback @@ -294,8 +294,8 @@ def revoked_token_loader(self, callback): {"msg": "Token has been revoked"} - The callback must be a function that takes no arguments, and returns - a Flask response. + *HINT*: The callback must be a function that takes **no** arguments, and returns + a *Flask response*. """ self._revoked_token_callback = callback return callback @@ -306,7 +306,7 @@ def user_loader_callback_loader(self, callback): automatically load an object when a protected endpoint is accessed. By default this is not used. - The callback must take one argument which is the identity JWT accessing + *HINT*: The callback must take **one** argument which is the identity JWT accessing the protected endpoint, and it must return any object (which can then be accessed via the :attr:`~flask_jwt_extended.current_user` LocalProxy in the protected endpoint), or `None` in the case of a user not being @@ -327,8 +327,8 @@ def user_loader_error_loader(self, callback): {"msg": "Error loading the user "} - The callback must be a function that takes one argument, which is the - identity of the user who failed to load, and must return a Flask response. + *HINT*: The callback must be a function that takes **one** argument, which is the + identity of the user who failed to load, and must return a *Flask response*. """ self._user_loader_error_callback = callback return callback @@ -339,9 +339,9 @@ def token_in_blacklist_loader(self, callback): a protected endpoint is accessed and will check if the JWT has been been revoked. By default, this callback is not used. - The callback must be a function that takes one argument, which is the - decoded JWT (python dictionary), and returns `True` if the token - has been blacklisted (or is otherwise considered revoked), or `False` + *HINT*: The callback must be a function that takes **one** argument, which is the + decoded JWT (python dictionary), and returns *`True`* if the token + has been blacklisted (or is otherwise considered revoked), or *`False`* otherwise. """ self._token_in_blacklist_callback = callback @@ -356,9 +356,9 @@ def claims_verification_loader(self, callback): :meth:`~flask_jwt_extended.JWTManager.claims_verification_failed_loader` decorator. - This callback must be a function that takes one argument, which is the - custom claims (python dict) present in the JWT, and returns `True` if the - claims are valid, or `False` otherwise. + *HINT*: This callback must be a function that takes **one** argument, which is the + custom claims (python dict) present in the JWT, and returns *`True`* if the + claims are valid, or *`False`* otherwise. """ self._claims_verification_callback = callback return callback @@ -372,8 +372,8 @@ def claims_verification_failed_loader(self, callback): {"msg": "User claims verification failed"} - This callback must be a function that takes no arguments, and returns - a Flask response. + *HINT*: This callback must be a function that takes **no** arguments, and returns + a *Flask response*. """ self._verify_claims_failed_callback = callback return callback