def init_app(app): """Initialize JWT authentication mode.""" # set default config app.config.setdefault('JWT_SECRET_KEY', app.config['SECRET_KEY']) app.config.setdefault('AUTH_JWT_REALM', 'Login required') # JWT_EXPIRES only accepts 'timedelta', AUTH_JWT_EXPIRES also accepts 'int' jwt_expires = app.config.get('AUTH_JWT_EXPIRES') if jwt_expires is not None: if not isinstance(jwt_expires, dt.timedelta): jwt_expires = dt.timedelta(seconds=jwt_expires) app.config.setdefault('JWT_EXPIRES', jwt_expires) jwt_manager = JWTManager() jwt_manager.init_app(app) # because of the '_set_error_handler_callbacks' of flask_jwt_simple, # we have to override some exceptions callbacks to manually call our # handle_http_exception with an instanciated werkzeug HTTPException. jwt_manager.unauthorized_loader(_unauthorized_callback) jwt_manager.expired_token_loader(_expired_token_callback) jwt_manager.invalid_token_loader(_invalid_token_callback)
def test_manual_init_app(app): jwt_manager = JWTManager() jwt_manager.init_app(app) assert jwt_manager == app.extensions['flask-jwt-simple']