首页 文章

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

提问于
浏览
4

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

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

现在,这将创建没有身份验证的 endpoints .

// @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 explorer,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示例有 Headers :“www-authenticate:GoogleLogin realm =”https://www.google.com/accounts/ClientLogin“,service =”xapi“和

一般来说,我们如何为“App Engine Connected Android Project”生成的 endpoints 添加身份验证?

从Web应用程序,Android客户端或iOS客户端,我们可以从api资源管理器测试它吗?

1 回答

相关问题