【问题标题】:flask peewee REST api authentication to limit GETflask peewee REST api 身份验证以限制 GET
【发布时间】:2012-06-04 00:04:58
【问题描述】:

我正在使用 flask-peewee 构建一个新项目。此外,我正在使用烧瓶 peewee 中包含的 REST 接口。我按照这里的例子http://flask-peewee.readthedocs.org/en/latest/getting-started.html#exposing-content-using-a-rest-apihttp://flask-peewee.readthedocs.org/en/latest/rest-api.html#rest-api 所以我能够让我的 rest api 启动并运行,包括将 Auth 添加到 Rest。

但是我的问题是我无法保护 GET 请求。到目前为止,我已经浏览了 rest.py https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/rest.py 的源代码,但无法找到它的来源,尽管我确实找到了很多我以后可以使用的好东西。

默认情况下,REST API 似乎只保护 POST/PUT/DELETE 而不是 GET。

我不想使用烧瓶 url 安全,我希望烧瓶 peewee 有一些内置的方法。或者,如果这是一个已知的限制,那么有什么好的方法来处理这个

有什么想法吗?

【问题讨论】:

    标签: python rest flask peewee


    【解决方案1】:

    抱歉,您在查找此信息时遇到了问题。您可以在实例化身份验证类时指定需要身份验证的 HTTP 动词列表:

    # when instantiating your authentication
    api_auth = UserAuth(auth, protected_methods=['GET', 'POST', 'PUT', 'DELETE'])
    read_only_auth = UserAuth(auth) # default protected methods are POST/PUT/DELETE
    

    这是文档的链接:

    http://flask-peewee.readthedocs.org/en/latest/api.html#authenticating-requests-to-the-api

    【讨论】:

    • 非常感谢。这是一个很棒的烧瓶蓝图。很抱歉错过了文档中的内容。如果你有时间,我在哪里可以从你那里得到更多帮助。我需要一些关于编写自定义身份验证的指导。
    • 在 irc.freenode.net 上的#peewee 中联系我,或通过我的网站 (charlesleifer.com) 与我联系——乐于提供帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 2017-12-15
    • 2019-03-31
    • 2018-07-26
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多