Google Auth Library for Node.js

10.6.2 · active · verified Tue Apr 21

This is Google's officially supported client library for Node.js, providing comprehensive functionality for OAuth 2.0 authorization and authentication with Google APIs. It abstracts away the complexities of credential management, offering various authentication flows including Application Default Credentials (ADC), OAuth2 for user consent, JSON Web Tokens (JWT) for service-to-service communication, and direct access for Google Compute environments. The library is currently at version 10.6.2 and undergoes continuous development, with regular bug fixes and feature enhancements released typically on a monthly basis, as evidenced by recent changelog entries from March and February 2026. Key differentiators include its robust support for workload and workforce identity federation, impersonated credentials, and downscoped clients, making it suitable for a wide array of use cases from local development to complex multi-cloud deployments. It ships with TypeScript types, ensuring a typed developer experience.

Common errors

Warnings

Install

Imports

Quickstart

Installs the library and authenticates using Application Default Credentials (ADC) to obtain and verify an access token.

import { GoogleAuth } from 'google-auth-library';

async function authenticateWithADC() {
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
  });

  // Get the credentials for the default project
  const client = await auth.getClient();
  const accessToken = await client.getAccessToken();

  console.log('Successfully obtained access token using Application Default Credentials.');
  console.log('Access Token:', accessToken.token);

  // Example: Use the token to make an authenticated request
  // (This is illustrative; actual API calls would use a client library or fetch with Authorization header)
  if (accessToken.token) {
    const url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + accessToken.token;
    try {
      const response = await fetch(url);
      const data = await response.json();
      console.log('Token Info:', data);
    } catch (fetchError) {
      console.error('Failed to verify token:', fetchError);
    }
  } else {
    console.warn("No access token found. Ensure ADC is configured correctly (e.g., GOOGLE_APPLICATION_CREDENTIALS set or running on GCP).");
  }
}

authenticateWithADC().catch(console.error);

view raw JSON →