Accessing request headers in flask-restless preprocessor
In a normal Flask request-response cycle, the request
context is active when the Flask-Restful preprocessors and postprocessors are being run.
As such, using:
from flask import request, abortdef check_auth(instance_id=None, **kw): current_user = None auth = request.headers.get('Authorization', '').lower() try: type_, apikey = auth.split(None, 1) if type_ != 'your_api_scheme': # invalid Authorization scheme ProcessingException(message='Not Authorized', status_code=401) current_user = user_for_apikey[apikey] except (ValueError, KeyError): # split failures or API key not valid ProcessingException(message='Not Authorized', status_code=401)
should Just Work.