How to use the googleapis.google.options function in googleapis

To help you get started, we’ve selected a few googleapis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / google-api-nodejs-client / samples / compute / compute.js View on Github external
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const axios = require('axios');
const {google} = require('googleapis');
const compute = google.compute('v1');

// This example can be run from a GCE VM in your project.  The example fetches
// your project ID from the VM's metadata server, and then uses the Compute API
// to fetch the list of GCE zones in your project.
//
// See the defaultauth.js sample for an alternate way of fetching compute credentials.
//
google.options({auth: new google.auth.Compute()});
async function getZones() {
  // Get the projectId from the GCE metadata server
  const url = 'http://metadata/computeMetadata/v1/project/project-id';
  const headers = {'Metadata-Flavor': 'Google'};
  const res = await axios.get({url, headers});
  const project = res.data;

  const zonesResponse = await compute.zones.list({project});
  console.log(zonesResponse.data);
}

getZones().catch(console.error);
github firebase / extensions / budget-notifications / functions / index.js View on Github external
const _setAuthCredential = async () => {
  const res = await auth.getApplicationDefault();

  let client = res.credential;
  if (client.hasScopes && !client.hasScopes()) {
    client = client.createScoped([
      "https://www.googleapis.com/auth/cloud-billing",
      "https://www.googleapis.com/auth/cloud-platform",
    ]);
  }

  // Set credential globally for all requests
  google.options({
    auth: client,
  });
};
github GabeWeiss / GoogleIoTCoreApp / gcf / updateIoTConfig / index.js View on Github external
function setAuth(serviceAccount) {
  const jwtAccess = new google.auth.JWT();
  jwtAccess.fromJSON(serviceAccount);
  // Note that if you require additional scopes, they should be specified as a
  // string, separated by spaces.
  jwtAccess.scopes = 'https://www.googleapis.com/auth/cloud-platform';
  // Set the default authentication to the above JWT access.
  google.options({ auth: jwtAccess });
}
github skypager / skypager / src / features / google / src / GoogleIntegration.js View on Github external
const { omit, uniq } = this.lodash

    const scopes = uniq([
      ...DEFAULT_SCOPES,
      ...(this.settings.scopes || []),
      ...(options.scopes || []),
    ])

    const auth = await g.auth.getClient({ ...omit(options, 'fresh', 'cache', 'default'), scopes })

    if (options.cache) {
      this.hide('auth', auth)
    }

    if (options.default) {
      g.options({ auth })
    }

    return auth
  }
}
github skypager / skypager / src / features / google / src / GoogleIntegration.js View on Github external
if (
      typeof options.accessToken === 'string' &&
      this.runtime.fsx.existsSync(this.runtime.resolve(options.accessToken))
    ) {
      const accessToken = this.runtime.fsx.readJsonSync(this.runtime.resolve(options.accessToken))
      oauthClient.setCredentials(accessToken)
    } else if (typeof options.accessToken === 'object') {
      oauthClient.setCredentials(options.accessToken)
    }

    if (options.cache !== false) {
      this.hide('oauthClient', oauthClient)
    }

    if (options.default) {
      g.options({ auth: oauthClient })
    }

    return oauthClient
  }
github filipedeschamps / video-maker / robots / youtube.js View on Github external
function setGlobalGoogleAuthentication(OAuthClient) {
      google.options({
        auth: OAuthClient
      })
    }
github alvarowolfx / talking-plant-aog / functions / devices / cloudiotcore.js View on Github external
return google.auth.getApplicationDefault().then( ( { credential } ) => {              
      google.options( {
        auth : credential
      } )
      return google.discoverAPI( DISCOVERY_URL )
    } )
  }
github microsoft / google-play-vsts-extension / Tasks / google-play-release-bundle / googleutil.ts View on Github external
export function updateGlobalParams(globalParams: GlobalParams, paramName: string, value: any): void {
    tl.debug('Updating Global Parameters');
    tl.debug('SETTING ' + paramName + ' TO ' + JSON.stringify(value));
    globalParams.params[paramName] = value;
    google.options(globalParams);
    tl.debug('Global Params set to ' + JSON.stringify(globalParams));
}