【发布时间】:2021-12-10 07:57:20
【问题描述】:
我有一个托管在 Google Cloud Run 中的 Flask Web 应用程序,该应用程序由 https://mydomain.run.app 托管。
现在我正在尝试向其添加 google 身份验证。我在 GCP 的 credentials 下创建了 API。我在重定向 uri 中给出了https://mydomain.run.app/authorize,但是当我尝试从我的应用程序登录时,它会抛出重定向不匹配错误。 错误显示我http://mydomain.run.app/authorize。 不匹配的是 https 和 http 当我尝试在凭据 uri 中提供 http 时,它会抛出我
Invalid Redirect: This app has a publishing status of "In production". URI must use https:// as the scheme.
@app.route('/login/google')
def google_login():
google = oauth.create_client('google')
redirect_uri = url_for('authorize', _external=True,_scheme='https')
return google.authorize_redirect(redirect_uri)
@app.route('/authorize')
def authorize():
google = oauth.create_client('google')
token = google.authorize_access_token()
resp = google.get('userinfo')
user_info = resp.json()
user = oauth.google.userinfo()
session['profile'] = user_info
session.permanent = True
return redirect('/select')
【问题讨论】:
-
您的代码在调用 Google 身份验证端点时指定了 http 方案。
-
您可以建议任何 https 方案的参考或示例吗?
-
您在寻找什么参考资料?您的代码造成了问题。
-
我已将上面的代码添加到我的帖子中。我无法弄清楚我在哪里犯错。我是新来的。谢谢!
标签: flask google-cloud-platform google-oauth google-authentication redirect-uri-mismatch