Python flask_jwt_extended.JWTManager() Examples
The following are 2
code examples of flask_jwt_extended.JWTManager().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_jwt_extended
, or try the search function
.
Example #1
Source File: authorization.py From TensorHive with Apache License 2.0 | 6 votes |
def init_jwt(app): for key, value in AUTH.FLASK_JWT.items(): app.config[key] = value global jwt jwt = JWTManager(app) @jwt.token_in_blacklist_loader def is_token_on_blacklist(decrypted_token): jti = decrypted_token['jti'] return RevokedToken.is_jti_blacklisted(jti) @jwt.user_claims_loader def add_claims_to_access_token(current_user_id): try: current_user = User.get(current_user_id) roles = current_user.role_names except Exception: roles = [] finally: return {'roles': roles}
Example #2
Source File: __init__.py From Flask-GraphQL-Graphene-MySQL-Docker-StarterKit with MIT License | 4 votes |
def create_app(): app = Flask(__name__) app.config.from_object((set_environment_config())) jwt = JWTManager(app) @jwt.expired_token_loader def my_expired_token_callback(): return jsonify({ 'status': 401, 'sub_status': 42, 'msg': 'The token has expired' }), 401 db.init_app(app) from app.models.User import User from app.models.VerificationCode import VerificationCode @app.before_first_request def initialize_database(): db.create_all() @app.route('/') def hello_world(): return "Hello World" from app.schema import schema app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # for having the GraphiQL interface ) ) @app.teardown_appcontext def shutdown_session(exception=None): db.session.remove() return app