【问题标题】:How do I add Google Account authentication to Google Cloud Endpoints in Python如何在 Python 中将 Google 帐户身份验证添加到 Google Cloud Endpoints
【发布时间】:2013-02-28 04:03:57
【问题描述】:

我正在尝试为我的 Android 应用创建一个 Google Cloud Endpoints 后端,该应用使用用户的 Google 帐户进行身份验证。我发现 Java API 包含 OAuth 范围的注释,但 python 文档只对它进行了一次引用。

这是我在端点上使用的注释:

@endpoints.api(name='notes', version='v1',
           description='Notes API',
           allowed_client_ids=[CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
           audiences=[AUDIENCE],
           scopes=['https://www.googleapis.com/auth/userinfo.email'])

但是生成的代码没有任何作用域:

/**
 * Available OAuth 2.0 scopes for use with the .
 *
 * @since 1.4
 */
public class NotesScopes {

  private NotesScopes() {
  }
}

甚至生成的服务类似乎都缺少部分:

/**
 * The default encoded root URL of the service. This is determined when the library is generated
 * and normally should not be changed.
 *
 * @since 1.7
 */
public static final String DEFAULT_ROOT_URL = "https://None/_ah/api/";

/**
 * The default encoded service path of the service. This is determined when the library is
 * generated and normally should not be changed.
 *
 * @since 1.7
 */
public static final String DEFAULT_SERVICE_PATH = "notes/v1/";

我假设我缺少一些注释或配置选项。有谁知道它可能是什么?

【问题讨论】:

    标签: android python google-app-engine google-oauth google-cloud-endpoints


    【解决方案1】:

    注解中的scopes 属性未在Android 身份验证流程中使用,这是它未包含在生成的Java 代码中的原因之一。相反,Android 使用 ID 令牌,其中包含足够的信息来向后端表示您的用户/应用程序,而无需请求范围。

    【讨论】:

    • RE:“即使生成的服务类似乎也缺少部分:”,请参阅文档 developers.google.com/appengine/docs/python/endpoints/…None 出现在 DEFAULT_ROOT_URL 中,因为在 @ 之前没有指定 hostname 987654326@ 已运行。
    • 这里缺少的,我认为文档中还不清楚的是,您必须为受众使用 Web 客户端,而不是 Android 客户端。这似乎特别违反直觉,但一些更清晰的文档会有所帮助。网络上还有很多其他类似的问题,花了几个星期才拼凑出一个解决方案。也许在文档中添加一个部分,详细说明您必须在 apis 控制台中执行的操作,不仅仅是针对 android 的东西,而且最初的部分会有所帮助。
    猜你喜欢
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2017-07-06
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多