如何向Google云终端添加身份验证?

时间:2013-04-02 01:32:13

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

从Google Cloud Endpoint开始,tic tac toe示例(请参阅https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java

然后,在最新的Android Ellipse插件中通过Ellipse创建一个“AppEngine Connected Android Project”(参见https://developers.google.com/eclipse/docs/endpoints-androidconnected-gae

现在,这会创建没有身份验证的端点。

// @Api(name = "messageEndpoint")
//NO AUTHENTICATION; OPEN ENDPOINT!

现在尝试使用tic tac toe应用程序添加身份验证作为示例。

@Api(name = "messageEndpoint",
version = "v1",
clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID, Ids.IOS_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID},
audiences = {Ids.ANDROID_AUDIENCE}

如果是oauth异常,请添加以下内容:

//public void sendMessage(@Named("message") String message)
  //throws IOException {

public void sendMessage(@Named("message") String message)
  throws OAuthRequestException,IOException {

使用api资源管理器测试,https:// [your-app-id] .appspot.com / _ah / api / explorer,我将[your-app-id]替换为我的特定应用程序ID。

POST https://[your-app-id].appspot.com/_ah/api/messageEndpoint/v1/sendMessage/test
X-JavaScript-User-Agent:  Google APIs Explorer

503 Service Unavailable


cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  193
content-type:  application/json; charset=UTF-8
date:  Mon, 01 Apr 2013 22:57:17 GMT
expires:  Mon, 01 Apr 2013 22:57:17 GMT
server:  GSE

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "java.lang.NoClassDefFoundError: Could not initialize class com.brooklynmarathon.citysync.endpoints.EMF"
   }
  ],
  "code": 503,
  "message": "java.lang.NoClassDefFoundError: Could not initialize class com.brooklynmarathon.citysync.endpoints.EMF"
 }
}

我尝试使用我下载的tic tac toe应用程序(感谢Google Dev Rel)并在此处构建并上传了https://brooklynmarathon.appspot.com/_ah/api/explorer

当我尝试访问分数列表时,我看到:

GET https://brooklynmarathon.appspot.com/_ah/api/tictactoe/v1/score

X-JavaScript-User-Agent:  Google APIs Explorer


Response


401 Unauthorized

- Hide headers -

cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  193
content-type:  application/json; charset=UTF-8
date:  Tue, 02 Apr 2013 01:14:40 GMT
expires:  Tue, 02 Apr 2013 01:14:40 GMT
server:  GSE
www-authenticate:  GoogleLogin realm="https://www.google.com/accounts/ClientLogin", service="xapi"

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "com.google.appengine.api.oauth.OAuthRequestException: Invalid user.",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "com.google.appengine.api.oauth.OAuthRequestException: Invalid user."
 }
}

我的问题是为什么tic tac toe示例有标题:“www-authenticate:GoogleLogin realm =”https://www.google.com/accounts/ClientLogin“,service =”xapi“和

一般情况下,我们如何为“App Engine Connected Android Project”生成的端点添加身份验证?

来自网络应用程序,Android客户端或iOS客户端,我们可以从api资源管理器进行测试吗?

1 个答案:

答案 0 :(得分:2)

“一般情况下,我们如何为”App Engine Connected Android Project“生成的终端添加身份验证?”

这样做的说明如下:
https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls

您还可以在那里看到iOS和Javascript的说明(在后续页面中)。

在服务器端,您需要将User对象添加为端点方法的第一个参数。

我不知道你其他问题的答案。