Flask身份验证不适用于Zappa

时间:2019-12-23 20:33:17

标签: python python-3.x flask flask-login zappa

我有一个在本地运行的Flask应用。我通过Zappa将其部署在AWS Lambda上。一切正常,除了需要身份验证的部分。通常,第一次用户进入需要此页面的页面时,会弹出一个登录表单,用于验证凭据。 我使用以下代码:

from functools import wraps
from flask import request, Response


def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    return username == "XXX" and password == "XXX"


def authenticate():
    """Sends a 401 response that enables basic auth"""
    return Response(
        "Could not verify your access level for that URL.\n"
        "You have to login with proper credentials",
        401,
        {"WWW-Authenticate": 'Basic realm="Login Required"'},
    )


def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)

    return decorated

我需要登录的页面:

@app.route("/page", methods=["GET"])
@requires_auth
def page():
...

我的问题: 为什么在Zappa中不起作用?

0 个答案:

没有答案