0
votes

I've made no code changes all to the Google Sheets integration I have in my Chrome extension (internal use only in our company). Today, I'm getting a '403' error with the message "The request is missing a valid API key."

I am not using an API key and never have - just a Client ID. This has been great for years, up until today or yesterday.

My scopes are https://www.googleapis.com/auth/spreadsheets and https://www.googleapis.com/auth/userinfo.profile.

Any thoughts? Did something change here that I'm not aware of? I did see this: https://github.com/zquestz/omniauth-google-oauth2/issues/106 but the time frame doesn't jive with what I'm seeing.

1

1 Answers

1
votes

I was encountering the same problem and the fix was to manually set the OAuth2 token:

gapi.auth.setToken({access_token: oauthToken});

For context, here's the auth and initialization flow in my background.js:

var oauthToken;

chrome.identity.getAuthToken(
  {
    'interactive': true,
    'scopes': <scopes>,
  },
  function(token) {
    oauthToken = token;

    // load Google client APIs
    window.gapi_onload = authGapi;
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
      if ((request.readyState !== 4) || (request.status !== 200)) {
            return;
          }
      eval(request.responseText);
    };
    request.open('GET', 'https://apis.google.com/js/client.js');
    request.send();
    }
);

var authGapi = function() {
  gapi.auth.authorize({
        immediate: true,
        client_id: <clientId>,
        scope: <scopes>,
  },
  function(response) {
    gapi.client.init({
      discoveryDocs: [
        'https://sheets.googleapis.com/$discovery/rest?version=v4',
      ]
    }).then(function() {
      gapi.auth.setToken({access_token: oauthToken});
      });
  });
}