【问题标题】:OAuth2WebServerFlow works from localhost, but not from real AppEngine InstanceOAuth2WebServerFlow 适用于本地主机,但不适用于真实的 AppEngine 实例
【发布时间】:2014-12-22 23:54:32
【问题描述】:

我正在使用 OAuth2WebServerFlow 来获取用户的表格凭据以与 gdata/spreadsheets API 一起使用。我很难诊断这个问题,因为当我在本地运行应用程序时它可以完美运行。

这是我用来获取授权 URL 的 sn-p:

CLIENT_ID = 'my-id'
CLIENT_SECRET = 'my-secret'
SCOPE = 'https://spreadsheets.google.com/feeds'
flow_object = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, SCOPE, redirect_uri=self.REDIRECT_URL, access_type='online')
authorize_url = flow_object.step1_get_authorize_url()

本地(使用REDIRECT_URL = 'http://localhost:8080/this-path/') 这会产生:

https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fthis-path%2F&scope=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&client_id=my-id&response_type=code&access_type=online

在实时 App Engine 应用程序上(使用 REDIRECT_URL = 'http://my-app.appspot.com/this-path/') 这会产生:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds&redirect_uri=http%3A%2F%2Fmy-app.appspot.com%2Fthis-path%2F&response_type=code&client_id=my-id&access_type=online

应用程序配置如下:

CLIENT ID: my-id
EMAIL ADDRESS: my-id@developer.gserviceaccount.com
CLIENT SECRET:  my-secret
REDIRECT URIS:
    http://localhost:8080/
    http://my-app.appspot.com
    https://my-app.appspot.com
    http://my-app.appspot.com/this-path
    https://my-app.appspot.com/this-path
    http://my-app.appspot.com/this-path/
    https://my-app.appspot.com/this-path/
JAVASCRIPT ORIGINS
    http://localhost:8080
    http://my-app.appspot.com

转到本地生成的url版本我可以成功授予应用程序权限。但是在我的实时应用程序生成的 url 上,我得到一个 401,上面写着“错误:disabled_client OAuth 客户端被禁用”。

我觉得它可能只是一个配置错误。也许它在本地工作的事实只是一个红鲱鱼?也许我总是能够授予 localhost 这些权限?我真的对此一无所知,我们将不胜感激。

【问题讨论】:

    标签: google-app-engine oauth oauth-2.0 google-oauth gdata


    【解决方案1】:

    在应用配置中,redirect URL应该是这样http://localhost:8080/oauth2callback,据我了解oauth2callback在流程结束时授权token。请参阅文档 [1]。

    [1] OAUTH 2.0https://developers.google.com/api-client-library/python/guide/aaa_oauth#OAuth2WebServerFlow

    【讨论】:

    • 所以我理解正确,你是说你认为路径必须是“oauth2callback”吗?我可以稍后再试一下,但我持怀疑态度。特别是考虑到“oauth2callback”不在您用作参考的页面上的任何位置。
    猜你喜欢
    • 1970-01-01
    • 2017-11-26
    • 2017-03-16
    • 1970-01-01
    • 2020-02-10
    • 2019-04-23
    • 2018-11-15
    • 1970-01-01
    • 2013-11-05
    相关资源
    最近更新 更多