1. Loading the gapi client
Indeed the only way I have found to load the gapi client is to use a webview, as explained here. I have tested itand it works well but weirdly the authentication does not work at all, and Cloud Endpoints believes you're anonymous.
In addition communication from a webview to the rest of the world is pretty tricky (window.postMessage does not allow to send a response in a callback).
I think you will be better off calling directly the REST methods using AJAX requests, with a helper such as jQuery or other. You just have to set the Authorization
header using you access token, like this in jQuery :
$.ajax({
type:"GET",
beforeSend: function (request)
{
request.setRequestHeader("Authorization", "Bearer "+THE_ACCESS_TOKEN);
},
url: "https://yourapp.appspot.com/_ah/api/yourapi/v1/yourmethod",
success: function(msg) {
//Put here your callback
}
});
See below how to get the access token.
2. Authorization in Chrome Apps
You do not have to worry about the origin part in Chrome Apps, you simply need to generate a client id specific to the Chrome App, and use the Chrome Identity API to get authorization from the user. Check the Chrome Identity API documentation for more details.
Note that since you will need to create a new client id, you will need to update your Google Cloud Endpoint's configuration to add this client id to the list of authorized clients.