Max
Max

Reputation: 934

firebase hosting REST api reference error SCOPES is not defined

I'm following the Firebase hosting REST API documentation for this one (https://firebase.google.com/docs/hosting/api-deploy#raw-http-request)

Particularly the first part of the code

const {google} = require('googleapis');

console.log("access token: ", getAccessToken());

function getAccessToken() {
  return new Promise(function(resolve, reject) {
    var key = require('./service-account.json');
    var jwtClient = new google.auth.JWT(
      key.client_email,
      null,
      key.private_key,
      SCOPES,
      null
    );
    jwtClient.authorize(function(err, tokens) {
      if (err) {
        reject(err);
        return;
      }
      resolve(tokens.access_token);
    });
  });
}

But it throws this error and I can't seem to find this online? Am I making a mistake somewhere?

`ReferenceError` was thrown:
    ReferenceError: SCOPES is not defined

Thank you!

Upvotes: 2

Views: 356

Answers (1)

If you are using firebase hosting, the scope is firebase.hosting API.

Add the following above the function

const SCOPES = ["https://www.googleapis.com/auth/firebase.hosting"];

If you you other APIs, add them to the array.

Upvotes: 2

Related Questions