【问题标题】:Google Cloud Endpoints without Google Accounts没有 Google 帐户的 Google Cloud Endpoints
【发布时间】:2013-10-14 00:28:41
【问题描述】:
【问题讨论】:
标签:
google-app-engine
authentication
google-cloud-endpoints
【解决方案1】:
你不需要做任何事情。我在 app-engine 上有一个联合登录应用程序,我最近在其中添加了一个使用 Cloud Endpoints 的 Android 应用程序。您不必做任何特别的事情,只需将 User 参数放入您的函数中。在用户对象中,您将找到您必须授权才能访问数据的用户电子邮件。
@Api(name = "my_api",
version = "v1",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
clientIds = {Constants.AUTH_CLIENT,
Constants.AUTH_CLIENT_APIEXPLORER})
public class MyEndpoint {
@ApiMethod(name = "fistEndpoint")
public ResponseObject fistEndpoint(User user) throws OAuthRequestException {
if (user == null) {
throw new OAuthRequestException("Access denied!");
}
String email = user.getEmail();
//Authorize the request here
//make the ResponseObject and return it
}
}
创建端点访问后:
https://your-app.appspot.com/_ah/api/explorer 测试一下
更新: 以上示例仅限于 Google 帐户。如果您想要其他类型的帐户,可以查看此帖子:
Custom Authentication for Google Cloud Endpoints (instead of OAuth2)
【解决方案2】:
Google Cloud Endpoints 是无状态的,因此如果您不使用 Google 身份验证,则无法将用户电子邮件检索到端点中。
实际上,端点只是 http 请求,因此您可以将您的信息传递给 http 授权,就像不记名一样。您可以完全访问这些端点信息。
希望对你有帮助。