How to use Google Cloud Endpoints from within a Chrome App? -
i'm building chrome app, , i'd communicate server on cloud endpoints, there 2 problems i'm not sure how overcome:
- the google apis javascript library external script, can't use in page in chrome app. can copy source of library, , place in file in app's source?
- the client checks javascript origin, extension's origin of form
chrome-extension://extension_id
, developer console doesn't accept javascript origin.
how around these issues?
1. loading gapi client
indeed way have found load gapi client use webview, as explained here. have tested itand works weirdly authentication not work @ all, , cloud endpoints believes you're anonymous.
in addition communication webview rest of world pretty tricky (window.postmessage not allow send response in callback).
i think better off calling directly rest methods using ajax requests, helper such jquery or other. have set authorization
header using access token, 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 callback } });
see below how access token.
2. authorization in chrome apps
you not have worry origin part in chrome apps, need generate client id specific chrome app, , use chrome identity api authorization user. check chrome identity api documentation more details.
note since need create new client id, need update google cloud endpoint's configuration add client id list of authorized clients.
Comments
Post a Comment