【发布时间】:2016-08-20 22:20:30
【问题描述】:
我目前正在使用 Google Cloud Endpoint 生成的 JavaScript 客户端对我的后端进行 API 调用。问题是我的页面的 cookie 没有被添加到 HTTP 请求中。如何将 Gitkit gtoken cookie 添加到我的请求中。
- 后端是 Google App Engine Java
- 使用 Goole Cloud Endpoints 构建我的 API
- 使用 Google Cloud Endpoints JavaScript Web 客户端加载如下
gapi.client.load('myApi', 'v1', resourceLoaded, 'https://my-project-id.appspot.com/_ah/api');
我已经在后端配置了 Google Cloud Endpoints 以允许使用 cookie。 auth = @ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE)
我的端点如下所示。
@ApiMethod(path = "user-account")
public UserAccount get(HttpServletRequest httpRequest) {
GitkitUser gitkitUser = Gitkit.validate(httpRequest); // returns null
Cookie[] cookies = httpRequest.getCookies();
log.severe("# of cookies: " + cookies.length);
for (Cookie cookie : cookies) {
log.severe("cookie name: " + cookie.getName());
log.severe("cookie value: " + cookie.getValue());
}
/*
* Logs 1 for # of cookies, with a cookie name of "G_ENABLED_IDPS"
* a value of "google". No gtoken cookie, even though I have
* checked and there is one!
*/
...
}
我正在使用 Google Cloud Endpoints JS 客户端进行调用。
gapi.client.myApi.userAccountResource.get().execute(function (resp){
...
});
我需要做些什么来确保 Endpoints JS 客户端在其请求中包含 gtoken cookie?
【问题讨论】:
-
开放赏金,仍然没有答案!我可以做些什么来让这个问题更清楚吗?
-
嗨 Marc,您可以添加 cookie 存储 + 请求标头的屏幕截图并创建 plunker/jsfiddle/jsbin 来重现问题。
-
@AlexanderTrakhimenok 你的意思是浏览器端的cookies存储吗?
-
是的,cookie 可能未设置或未发送到服务器。您需要定位问题所在。如果它是通过浏览器通过有线发送的,那么问题出在服务器端。如果它在 cookie 存储中但未发送,则为客户端问题。如果它不在存储中,则没有任何东西要发送,而要找出它们根本不在客户端的原因是另一个问题。
-
您可以在浏览器的开发工具中查看 cookie 和请求标头。是的,如果未过期,cookie 会自动发送并匹配主机和路径前缀。
标签: google-app-engine cookies google-cloud-endpoints google-identity-toolkit