Python Google Apps Engine 上的 Flask REST 身份验证

Python Flask REST authentication on Google Apps Engine

我有一些 REST 服务的 Python Flask 实现,我想 运行 在 Google App Engine (GAE) 上。我有服务 运行ning,但现在我想添加一些基本身份验证,以帮助为我的服务和数据添加安全层。我已尝试关注 Miguel 的优秀文章:http://blog.miguelgrinberg.com/post/restful-authentication-with-flask

但是我卡在了如下代码部分:

from flask.ext.httpauth import HTTPBasicAuth
auth = HTTPBasicAuth()

@app.route('/api/resource')
@auth.login_required
def get_resource():
    return jsonify({ 'data': 'Hello, %s!' % g.user.username })

据我所知,GAE 支持 httpauthHTTPBasicAuth 的使用。那是对的吗?或者有没有办法在那里使用这些库?对于 GAE,类似的东西会是什么?我不想添加像 OpenID 这样的花哨的身份验证层和类似的东西 - 我不想要求我的所有用户都有一个 Google 帐户。我真的只是在寻找 GAE 允许的最直接的身份验证。

You can include additional pure-python third-party packages, you can do so by setting up vendoring. Vendoring allows you to install packages to a subdirectory of your project and include them in your code. - Vendoring Third-party Packages

  1. cd <your_appengine_project_directory>
  2. 在项目的根目录中创建或修改 appengine_config.py 以包含以下内容:

    from google.appengine.ext import vendor
    
    vendor.add('lib')
    pip install -r requirements.txt -t lib/
    

    或最后一条命令:

    pip install Flask-HTTPAuth -t lib/
    

请参阅 https://github.com/GoogleCloudPlatform/appengine-python-flask-skeleton 了解有关开始使用 GAE 的烧瓶框架