error : redirect_uri_mismatch :: The redirect_uri MUST match the registered callback URL
error : redirect_uri_mismatch :: The redirect_uri MUST match the registered callback URL
所以我正在尝试使用 Github OAuth API 在 Flask 中学习 OAuth,我正在为此使用 flask_dance
库。我可以在 Github 和 return 上验证自己回到我的应用程序,但在其显示 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 mismatch
。
我正在阅读文档 here 并了解到我们可以从请求中删除 redirect_uri
参数,但我不确定该怎么做。
(我在 Windows 10 )
你能帮忙的话,我会很高兴。谢谢。
App.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
Flask-Dance 的文档说代码创建了一个蓝图 "github",其中包含两个视图“/github”和“/github/authorized”。蓝图还配置了 url_prefix 的“/login”,因此您的回调 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.
所以我正在尝试使用 Github OAuth API 在 Flask 中学习 OAuth,我正在为此使用 flask_dance
库。我可以在 Github 和 return 上验证自己回到我的应用程序,但在其显示 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 mismatch
。
我正在阅读文档 here 并了解到我们可以从请求中删除 redirect_uri
参数,但我不确定该怎么做。
(我在 Windows 10 )
你能帮忙的话,我会很高兴。谢谢。
App.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
Flask-Dance 的文档说代码创建了一个蓝图 "github",其中包含两个视图“/github”和“/github/authorized”。蓝图还配置了 url_prefix 的“/login”,因此您的回调 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.