7
votes

I am currently making API calls to my backend using the Google Cloud Endpoint generated JavaScript Client. The problem is the cookies for my page are not being added to the HTTP requests. How can I add the Gitkit gtoken cookie to my request.

  • Backend is Google App Engine Java
  • Using Goole Cloud Endpoints to build my API
  • Using the Google Cloud Endpoints JavaScript web client loaded 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 looks 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 am making calls with the Google Cloud Endpoints JS client as so.

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

Is there something I have to do to make sure the Endpoints JS client includes the gtoken cookie in it's request?

1
Open bounty and still no answers! Is there something I can do to make this question more clear?Marc M.
Hi Marc, you can add screenshots of cookies storage + request headers and create a plunker/jsfiddle/jsbin to reproduce the problem.Alexander Trakhimenok
@AlexanderTrakhimenok Do you mean cookies storage on the browser side?Marc M.
Yes, there are chances that cookies are not set or not send to server. You need to localize where is a problem. If it's sent over wire by browser then issue is on server side. If it's in cookies storage but not sent it's client issue. If it's not in storage there is just nothing to sent and it's a different problem to find out why they are not at client at all.Alexander Trakhimenok
You can view cookies & requests headers in dev tools of your browser. And yes, cookies are send automatically if not expired and match to host & path prefix.Alexander Trakhimenok

1 Answers

2
votes

You better add screenshots of cookies storage + request headers and create a plunker/jsfiddle/jsbin to reproduce the problem.

There are chances that cookies are not set or not send to server. You need to localize where is a problem. If it's sent over wire by browser then issue is on server side. If it's in cookies storage but not sent it's client issue. If it's not in storage there is just nothing to sent and it's a different problem to find out why they are not at client at all.

You can view cookies & requests headers in devtools of your browser. And yes, cookies are send automatically if not expired and match to host & path prefix.