How to use the google-auth-library.GoogleAuth function in google-auth-library

To help you get started, we’ve selected a few google-auth-library 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-auth-library-nodejs / samples / headers.js View on Github external
async function main() {
  // create auth instance with custom scopes.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
  });
  const projectId = await auth.getProjectId();
  const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;

  // obtain an authenticated client
  const client = await auth.getClient();
  // Use the client to get authenticated request headers
  const headers = await client.getRequestHeaders();
  console.log('Headers:');
  console.log(headers);

  // Attach those headers to another request, and use it to call a Google API
  const res = await fetch(url, {headers});
  const data = await res.json();
  console.log('DNS Info:');
github googleapis / google-auth-library-nodejs / samples / keyfile.js View on Github external
async function main(
  // Full path to the sevice account credential
  keyFile = process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
  const auth = new GoogleAuth({
    keyFile: keyFile,
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
  });
  const client = await auth.getClient();
  const projectId = await auth.getProjectId();
  const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;
  const res = await client.request({url});
  console.log('DNS Info:');
  console.log(res.data);
}
github GoogleCloudPlatform / cloud-for-marketing / marketing-analytics / activation / common-libs / nodejs-common / apis / auth_client.js View on Github external
getServiceAccount(keyFile = this.serviceAccountKeyFile) {
    console.log(`Get Service Account's key file: ${keyFile}`);
    return Promise.resolve(new GoogleAuth({
      keyFile: keyFile,
      scopes: this.scopes,
    }));
  }
}
github googleapis / google-auth-library-nodejs / samples / adc.js View on Github external
async function main() {
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
  });
  const client = await auth.getClient();
  const projectId = await auth.getProjectId();
  const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;
  const res = await client.request({url});
  console.log('DNS Info:');
  console.log(res.data);
}
github firebase / firebase-tools / src / requireAuth.ts View on Github external
function getAuthClient(config: GoogleAuthOptions): GoogleAuth {
  if (authClient) {
    return authClient;
  }

  authClient = new GoogleAuth(config);
  return authClient;
}
github stephenplusplus / google-auto-auth / index.js View on Github external
var createAuthClientPromise = (resolve, reject) => {
      var config = this.config;
      var keyFile = config.keyFilename || config.keyFile;

      this.googleAuthClient = new GoogleAuth();

      var addScope = (err, authClient, projectId) => {
        if (err) {
          reject(err);
          return;
        }

        if (authClient.createScopedRequired && authClient.createScopedRequired()) {
          if (!config.scopes || config.scopes.length === 0) {
            var scopeError = new Error('Scopes are required for this request.');
            scopeError.code = 'MISSING_SCOPE';
            reject(scopeError);
            return;
          }
        }
github googleapis / nodejs-gce-images / src / index.ts View on Github external
constructor(config?: GCEImagesConfig) {
    config = config || {};
    config.scopes = ['https://www.googleapis.com/auth/compute'];
    this._auth = config.authClient || new GoogleAuth(config);
    this.OS_URLS = GCEImages.OS_URLS;
  }
github googleapis / gcs-resumable-upload / src / index.ts View on Github external
constructor(cfg: UploadConfig) {
    super();
    streamEvents(this);

    cfg = cfg || {};

    if (!cfg.bucket || !cfg.file) {
      throw new Error('A bucket and file name are required');
    }

    cfg.authConfig = cfg.authConfig || {};
    cfg.authConfig.scopes =
        ['https://www.googleapis.com/auth/devstorage.full_control'];
    this.authClient = cfg.authClient || new GoogleAuth(cfg.authConfig);

    this.bucket = cfg.bucket;
    this.file = cfg.file;
    this.generation = cfg.generation;
    this.kmsKeyName = cfg.kmsKeyName;
    this.metadata = cfg.metadata || {};
    this.offset = cfg.offset;
    this.origin = cfg.origin;
    this.userProject = cfg.userProject;

    if (cfg.key) {
      /**
       * NOTE: This is `as string` because there appears to be some weird kind
       * of TypeScript bug as 2.8. Tracking the issue here:
       * https://github.com/Microsoft/TypeScript/issues/23155
       */
github googleapis / nodejs-spanner / src / index.ts View on Github external
const config = {
      baseUrl: options.servicePath || gapic.v1.SpannerClient.servicePath,
      protosDir: path.resolve(__dirname, '../protos'),
      protoServices: {
        Operations: {
          path: 'google/longrunning/operations.proto',
          service: 'longrunning',
        },
      },
      scopes: ['https://www.googleapis.com/auth/cloud-platform'],
      packageJson: require('../../package.json'),
    } as {} as GrpcServiceConfig;
    super(config, options);
    this.options = options;
    this.auth = new GoogleAuth(this.options);
    this.clients_ = new Map();
    this.instances_ = new Map();


    /**
     * Get a list of {@link Instance} objects as a readable object stream.
     *
     * Wrapper around {@link v1.InstanceAdminClient#listInstances}.
     *
     * @see {@link v1.InstanceAdminClient#listInstances}
     * @see [ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)
     *
     * @method Spanner#getInstancesStream
     * @param {GetInstancesRequest} [query] Query object for listing instances.
     * @returns {ReadableStream} A readable stream that emits {@link Instance}
     *     instances.