def authenticate_requests(*args, **kwargs): if (global_config.DEBUG): app.ext_logger.info( request.endpoint.replace(":", "/").replace(".", "/").lower()) # authenticate users here! if hasattr(app, "authentication_function"): app.authentication_function(global_config.X_AUTH_TOKEN) return func(*args, **kwargs)
def authenticate_requests(self, *args, **kwargs): """ The authentication_function can be either empty, which results in all requests being taken as granted and authenticated. Otherwise the authentication_function must not return when the authentication is successful otherwise it should raise an exception explaining the error (containing message and status_code). """ # authenticate users here! try: if hasattr(app, "authentication_function"): app.authentication_function(self) return func(self, *args, **kwargs) else: return func(self, *args, **kwargs) except HTTPException as e: return serialize({"errors": [e.message]}), e.status_code except Exception as e: return serialize({"errors": [str(e)]}), 500