如何在Python中为Google Cloud Endpoints添加Google账户认证
我正在为我的安卓应用创建一个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/";
我在想,可能是我漏掉了某个注解或者配置选项。有没有人知道可能是什么呢?
1 个回答
0
在这个注解中的 scopes
属性在安卓的认证流程中并没有被使用,这也是为什么它没有出现在生成的Java代码里的原因之一。相反,安卓使用的是一个ID令牌,这个令牌里面包含了足够的信息,可以让后端识别你的用户或应用,而不需要请求特定的权限范围。