Reputation: 26
I am using OAuth and Chrome Identity in my Chrome App to communicate with a Spreadsheet (Google Spreadsheet API). The problem is, the sheet needs to be public and/or shared with the developer account in order to work (for some reasons). I am assuming it's because the developer account owns the Google Cloud Platform project which owns the service account that's used by the Chrome App.
So my question is that how can we ask Chrome to use the logged-in Google account credential instead? So if A has ownership of a sheet, then A should be able to use the App to access the the sheet WITHOUT having to share the sheet with the developer.
So the below code WORKS, as long as the developer account is an editor of the sheet. How do I change it so it uses the user account instead?
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
var spreadsheetId = "SHEET_ID";
var sheetId = "0";
var range = "Sheet1!A1";
var respString;
var apiURL = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/" + range;
var objectHTTP;
objectHTTP = new XMLHttpRequest();
objectHTTP.onreadystatechange = function() {
if (objectHTTP.readyState == 4 && objectHTTP.status == 200) {
respString = objectHTTP.responseText;
}
respString = objectHTTP.responseText;
};
objectHTTP.open("GET", apiURL, false);
objectHTTP.setRequestHeader('Authorization', 'Bearer ' + token);
objectHTTP.send();
console.log(respString);
});
The code (objectHTTP.send part) fails with a 403 even if I am logged in as the owner of the private sheet.
Oh, it's interesting that I am not getting the consent screen when I use the getAuthToken method.
Upvotes: 1
Views: 422
Reputation: 2519
Chrome Identity use the Chrome Browser's identity it seems... Not your logged in "Google Account". So if your Chrome Browser user is A but you are signing in on B account, it apparently still thinks you are A.
Upvotes: 1