Flask身份验证不适用于Zappa

问题描述 投票:0回答:1

我有一个可以在本地运行的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中不起作用?

python python-3.x flask flask-login zappa
1个回答
0
投票

您是否已解决此问题?我也面临着同样的问题,并停留在这里。如果可能的话,您可以分享一下发现吗?

© www.soinside.com 2019 - 2024. All rights reserved.