Adding auth decorators to flask restx
Is it possible to reach the decorator from the view_function?
Well... it is possible, but I wouldn't recommend it. Here's an example
Is it possible to know whether the endpoint is a restx resource or aplain rest function?
You probably can inspect the func and figure out if it's from restx, maybe looking at __qualname__
, but then again, I`d wouldn't recommend it.
Is there a better way to do what I'm trying to achieve?
I would go one of these solutions:
- Explicitly decorate view_funcs and resources that do need authentication, instead of the other way around
- Create a blueprint for public endpoints, a blueprint for protected endpoints with the
before_request
decorator for authorization