本文整理汇总了Python中flask_jwt_extended.JWTManager方法的典型用法代码示例。如果您正苦于以下问题:Python flask_jwt_extended.JWTManager方法的具体用法?Python flask_jwt_extended.JWTManager怎么用?Python flask_jwt_extended.JWTManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_jwt_extended
的用法示例。
在下文中一共展示了flask_jwt_extended.JWTManager方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_jwt
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import JWTManager [as 别名]
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}
示例2: create_app
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import JWTManager [as 别名]
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