问题
Working on a Flask application which will have separate classes of routes to be authenticated against: user routes and host routes(think Airbnb'esque where users and hosts differ substantially).
Creating a single verify_password callback and login_required combo is extremely straightforward, however that isn't sufficient, since some routes will need host authentication and others routes will necessitate user authentication. Essentially I will need to have one verify_password/login_required for user and one for host, but I can't seem to figure out how that would be done since it appears that the callback is global in respect to auth's scope.
回答1:
The way I intended that to be handled is by creating two HTTPAuth objects. Each gets its own verify_password
callback, and then you can decorate each route with the decorator that is appropriate.
来源:https://stackoverflow.com/questions/31284225/multiple-verify-password-callbacks-on-flask-httpauth