繁体   English   中英

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

[英]How to add authentication to google cloud endpoints?

从Google Cloud Endpoint井字游戏示例开始(请参阅https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java

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

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

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

现在,以井字游戏应用程序为例,尝试添加身份验证。

@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进行测试,我用特定的应用程序ID替换了[your-app-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."
 }
}

我的问题是为什么井字游戏示例的标头为:“ www-authenticate:GoogleLogin realm =“ https://www.google.com/accounts/ClientLogin”,service =“ xapi”和

通常,我们如何向“与App Engine连接的Android项目”生成的端点添加身份验证?

通过Web应用程序,Android客户端或iOS客户端,我们可以在api资源管理器中对其进行测试吗?

“总的来说,我们如何向“与App Engine连接的Android项目”生成的端点添加身份验证?”

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

您还将在那里(随后的页面)上看到有关iOS和Javascript的说明。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM