gpt4 book ai didi

python-2.7 - 错误:redirect_uri_mismatch::redirect_uri 必须与注册的回调 URL 匹配

转载 作者:行者123 更新时间:2023-12-05 03:06:17 25 4
gpt4 key购买 nike

所以我正在尝试使用 Github OAuth API 在 Flask 中学习 OAuth,我正在为此使用 flask_dance 库。我能够在 Github 上验证自己并返回到我的应用程序,但在它显示 404 Not Found Error 并且在 url 中它的 http://localhost:5000/login/authorized?error =redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application... ,回调 url 似乎是正确的,因为它是我在 github 上给出的,但仍然显示 redirect_uri 不匹配。我正在阅读文档 here并且知道我们可以从请求中删除 redirect_uri 参数,但我不确定该怎么做。(我在 Windows 10 上)
你能帮忙的话,我会很高兴。谢谢。

shown here

应用.py
from flask import Flask, redirect, url_for
from werkzeug.contrib.fixers import ProxyFix
from flask_dance.contrib.github import make_github_blueprint, github

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
app.secret_key = "supersekrit"
blueprint = make_github_blueprint(
client_id="xxxxxxxxx",
client_secret="xxxxxxxx",
)
app.register_blueprint(blueprint, url_prefix="/login")

@app.route("/signup")
def index():
if not github.authorized:
return redirect(url_for("github.login"))
resp = github.get("/user")
assert resp.ok
return "You are @{login} on GitHub".format(login=resp.json()["login"])

if __name__ == "__main__":
app.run(debug=True)

最佳答案

您的回调 URL 不正确 - 应该是 http://localhost:5000/login/github/authorized

enter image description here

Flask-Dance 的文档说代码创建了一个蓝图“github”,其中有两个 View “/github”和“/github/authorized”。该蓝图还配置了“/login”的 url_prefix,因此您的回调 URL 需要为 http://localhost:5000/login/github/authorized。 .

This code makes a blueprint that implements the views necessary to be a consumer in the OAuth dance. The blueprint has two views: /github, which is the view that the user visits to begin the OAuth dance, and /github/authorized, which is the view that the user is redirected to at the end of the OAuth dance. Because we set the url_prefix to be /login, the end result is that the views are at /login/github and /login/github/authorized. The second view is the “authorized callback URL” that you must tell GitHub about when you create the application.

关于python-2.7 - 错误:redirect_uri_mismatch::redirect_uri 必须与注册的回调 URL 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com