Enable cookies in HTTP requests when using the Google Cloud Endpoints JavaScript client

I am currently making API calls for my backend using the Google Cloud Endpoint JavaScript client. The problem is that cookies for my page are not added to HTTP requests. How to add a gitkit gtoken cookie to my request.

  • Backend is Google App Engine Java
  • Using Goole Cloud Endpoints to Build My API
  • Using the Google Cloud Clouds Google web client downloaded as follows gapi.client.load('myApi', 'v1', resourceLoaded, 'https://my-project-id.appspot.com/_ah/api');

I have already configured Google Cloud Endpoints on the backend to allow cookies. auth = @ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE)

My endpoint is as follows.

 @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! */ ... } 

I make calls with the Google Cloud Endpoints JS client this way.

 gapi.client.myApi.userAccountResource.get().execute(function (resp){ ... }); 

Is there something I have to do to make sure that the Endpoints JS client contains a gtoken cookie in it?

+7
google-app-engine cookies google-identity-toolkit google-cloud-endpoints
source share
1 answer

You better add screenshots of cookie cookies + request headers and create the / jsfiddle / jsbin plunk to reproduce the problem.

It is likely that cookies are not set or are not sent to the server. You need to localize where the problem is. If it is sent through a wire through a browser, then the release is server-side. If it is stored in a cookie but does not send it to the client. If this is not in the store, then there is simply nothing to send, and this is another problem to find out why they are not in the client at all.

You can view the headers of cookies and requests in the devtools of your browser. And yes, cookies are automatically sent if they have not expired and match the host prefix and path.

+2
source

All Articles