Question

For my current project i want to use Cloud Endpoints and Cloud Storage API at the same time.

When you authenticate for cloud endpoints the example tic-tac-toe app from Google states that one should set the access_token to be the id_token like this (see github repository):

var token = gapi.auth.getToken();
// Use id_token instead of bearer token
token.access_token = token.id_token;

However once the access_token is set to the id_token one cannot use the other google apis anymore. In my case the Cloud Storage API. The reason for this is that the access token is now invalid for them. For example, the cloud storage api returns Invalid credential. Before the access_token is set to the id_token, the access_token looks like this: ya29.AHES6ZTjklghkljghlkjfghkljsrdölizuklhlfghI_UTfghdfghCg. It gets replaced with the id_token that i don't want to post here because it's really long.

The two solutions that i can think of are:

  • Copy the gapi object, each with a separate auth-object and token. Use the one with the id_token for cloud endpoints and the other for the rest (i was unable to copy the object in a way that makes this possible though)
  • Remember the auth token somewhere and replace it depending on what api (cloud endpoints / other api) i call (this would probably need synchronization and is somewhat messy)

I'm very interested in solutions and feasible workarounds for this problem.

If you encounter this issue, please read the answer below and my comments. Once you've done that you'll understand that this question is actually more this question here: How do I test Cloud Endpoints with Oauth on devserver

I'll leave the question here in case someone searches for the terms inside.

Was it helpful?

Solution

The Python Tic Tac Toe sample appears to be in need of an update. ID tokens are no longer required in this particular case. (The Java example is using Google+ login, so it has slightly different requirements.)

You can leave out manipulation of the token, and it will automatically work for Endpoints and whatever other Google API you are calling. See the Python "Hello Endpoints" example for what this looks like (most notable for what isn't in it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top