flask-httpauth上的多个verify_password回调 [英] Multiple verify_password callbacks on flask-httpauth

查看:195
本文介绍了flask-httpauth上的多个verify_password回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发Flask应用程序,该应用程序将具有要针对其进行身份验证的单独的路由类别:用户路由和主机路由(请考虑一下Airbnb风格,其中用户和主机存在很大差异).

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).

创建单个verify_password回调和login_required组合非常简单,但是这还不够,因为某些路由需要主机认证,而其他路由则需要用户认证.从本质上讲,我将需要为用户提供一个verify_password/login_required,为主机提供一个,但由于回调似乎是针对auth范围的全局变量,因此我似乎无法弄清楚该怎么做.

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.

推荐答案

我打算处理的方式是创建两个HTTPAuth对象.每个路由都有自己的verify_password回调,然后您可以使用适当的装饰器来装饰每个路由.

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.

这篇关于flask-httpauth上的多个verify_password回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆