【问题标题】:adding an auth check to github webhooks using flask + python3使用flask + python3向github webhooks添加身份验证检查
【发布时间】:2021-04-30 03:42:38
【问题描述】:

我一直在尝试将身份验证添加到 github,但由于某种原因我的哈希值不匹配,

这是我的代码:

@app.route('/update', methods=["POST"])
def update():
    assert request.method == "POST"
    signature = request.headers.get("X-Hub-Signature")
    if not signature or not signature.startswith("sha1="):
        abort(400, "X-Hub-Signature required")

    sha_name, sinature = signature.split("=")
    if sha_name != "sha1":
        abort(501)

    # Create local hash of payload
    digest = hmac.new(github_secret.encode(), msg=request.data, digestmod="sha1").hexdigest()


    # Verify signature
    if not hmac.compare_digest(signature, digest):
        abort(400, "Invalid signature")

【问题讨论】:

    标签: python python-3.x flask github webhooks


    【解决方案1】:

    这个问题是针对所有未来的谷歌员工的,我使用了request.data,它是 None 因为内容类型标头是“application/x-www-form-urlencoded”,感谢answer 的解释,所以我不得不改用request.get_data()

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 2020-12-24
      • 2011-12-29
      • 1970-01-01
      • 2021-12-23
      • 2014-11-28
      相关资源
      最近更新 更多