2

我正在尝试为我的Android应用创建一个Google Cloud Endpoints后端,该后端使用用户的Google帐户进行身份验证。我发现Java API包含OAuth范围的注释,但python文档仅对此做出单一引用。如何将Google帐户身份验证添加到Python中的Google Cloud Endpoints

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

@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/"; 

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

回答

0

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

+1

RE:“即使生成的服务类似乎缺少了部分:”,请参阅文档https://developers.google.com/appengine/docs/python/endpoints/gen_clients,“无”显示在“ DEFAULT_ROOT_URL',因为在运行'endpointscfg.py'之前没有指定'hostname'。 – bossylobster 2013-03-01 02:40:35

+0

这里缺少的东西,我认为在文档中还不太清楚,是您必须为受众使用Web客户端,而不是Android客户端。这似乎特别反直觉,但一些更清晰的文档将有所帮助。在网络上也有许多其他问题,需要花费数周的时间才能将解决方案拼凑在一起。 也许在文档中添加一段文字,说明您必须在apis控制台中执行哪些操作,而不仅仅是针对android的东西,但最初的部分会有所帮助。 – rharter 2013-03-11 22:21:36

相关问题