python - 我们如何在自定义端点上使用 python-eve @requires_auth 装饰器?
问题描述
按照 Nicola https://nicolaiarocci.com/building-custom-endpoint-handlers-with-eve/关于 requires_auth 装饰器的示例,我无法让它按预期工作,我需要一些帮助。
本质上,它似乎适用于默认身份验证方法,但我需要它与我的自定义身份验证类一起使用。
在settings.py
我定义了一个资源..
my = {
'schema': {
'test': {
'type': 'string',
},
},
'authentication': clientAuth,
'resource_methods': ['GET', 'POST'],
}
DOMAIN = {
'my': my,
}
然后我定义了这样的clientAuth
类..
class clientAuth(TokenAuth):
def check_auth(self, token, allowed_roles, resource, method):
clients = app.data.driver.db['clients']
lookup = {'token': token}
if allowed_roles:
lookup['roles'] = {'$in': allowed_roles}
client = clients.find_one(lookup)
if client:
slug = client['slug']
add_db_to_config(app, slug)
self.set_mongo_prefix(slug)
return client
我的自定义端点看起来像这样..
@app.route('/test')
@requires_auth("my")
def my():
# stuff
我希望(可能是错误的)装饰器中的参数应该使用域中定义的身份验证my
方法?requires_auth
my
如果我错了,如何在我的自定义端点中使用自定义身份验证类?
谢谢!
解决方案
推荐阅读
- c++ - 文件名后的 Clang 关键字
- css - Material-UI 中的 JssProvider 没有将我的自定义生产前缀应用于 CSS
- android - 再次按返回退出 android studio
- ruby-on-rails - 活动管理导轨中的分页计数问题
- c++ - 如何 C++ 编译静态第三方库,其中包含其他人在主应用程序中使用的另一个库
- unity3d - 我需要白色的碎片在马路的顶部,而不是在马路后面
- c++ - 带有表达式模板的多维数组模板类
- apache-spark - spark中用于添加新列的withcolumn()未显示结果
- vb.net - 关于动态添加的右键菜单添加点击事件的问题
- python - 在 Python 中使用贪心特征选择算法进行线性回归