[localhost和pythonanywhere上的OAuth

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

我正在制作一个日历应用程序,它允许用户授予访问其Google日历的权限,然后我的应用程序将允许他们查看和编辑以我自己的自定义样式显示的日历。

基于此Google "quickstart" sample

目前在本地运行正常,但是到目前为止,在pythonanywhere.com(网址为http://myname.pythonanywhere.com)上托管时,我无法使它运行。

[使用我的工作本地版本,我正在使用的certificate.json文件以"installed":开头,其AFAICT对应于“桌面应用程序”,并且"redirect_uris":包含["urn:ietf:wg:oauth:2.0:oob", "http://localhost”]。 (“ http://localhost”很有意义,但我不知道为什么还有第二个uri“ urn:ietf:wg:oauth:2.0:oob”)

{
    "installed": {
        "client_id": "XXXXXXXXXXXXXXXX.apps.googleusercontent.com",
        "project_id": "my_great_calendar",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "XXXXXXXXXXXXX",
        "redirect_uris": [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
}

如果我错了,请更正我,但是我假设当在myname.pythonanywhere.com上托管时,此certificate.json文件可能无法工作,我需要创建一个新文件(在Google的“ API和服务”页面上将该项目声明为“ Web应用程序”吗?并告诉Google我的重定向uri是“ http://myname.pythonanywhere.com”?

[如果有一种方法可以在本地和pythonanywhere上都可以使用单个凭据。

python flask oauth-2.0 pythonanywhere
1个回答
0
投票

转到API和服务

    转到凭证
  • 查找您的客户ID
  • 单击编辑(铅笔图标)
  • 在“授权重定向URI”下,您可以添加更多它们。
  • 保存
  • 然后JSON将包含两个重定向URI。我不知道他们的库如何选择要使用的库,因此您可能想通过传递redirect_uri参数来明确指定它:
  • flow = Flow.from_client_secrets_file('client_secrets.json', redirect_uri='http://blah.pythonanywhere.com/')

    [要知道要使用哪一个,您可以在启动服务器时通过一些配置(例如环境变量或命令行标志),或者让服务器通过查看主机头自动检测到它。

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