本文整理匯總了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