{"id":15629,"library":"google-auth-library","title":"Google Auth Library for Node.js","description":"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.","status":"active","version":"10.6.2","language":"javascript","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-node-core","tags":["javascript","google","api","google apis","client","client library","typescript"],"install":[{"cmd":"npm install google-auth-library","lang":"bash","label":"npm"},{"cmd":"yarn add google-auth-library","lang":"bash","label":"yarn"},{"cmd":"pnpm add google-auth-library","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for making HTTP requests, frequently updated in sync with the auth library.","package":"gaxios","optional":false}],"imports":[{"note":"The primary entry point for Application Default Credentials (ADC) and general credential management. The library is primarily ESM-first, so 'require' can lead to issues in mixed environments.","wrong":"const GoogleAuth = require('google-auth-library').GoogleAuth;","symbol":"GoogleAuth","correct":"import { GoogleAuth } from 'google-auth-library';"},{"note":"Used for user-based OAuth 2.0 flows. This is a named export, not a default export.","wrong":"import OAuth2Client from 'google-auth-library';","symbol":"OAuth2Client","correct":"import { OAuth2Client } from 'google-auth-library';"},{"note":"For authentication using JSON Web Tokens (JWTs), typically with service accounts. Like other main exports, it's a named export in an ESM-preferred package.","wrong":"const JWT = require('google-auth-library').JWT;","symbol":"JWT","correct":"import { JWT } from 'google-auth-library';"}],"quickstart":{"code":"import { GoogleAuth } from 'google-auth-library';\n\nasync function authenticateWithADC() {\n  const auth = new GoogleAuth({\n    scopes: 'https://www.googleapis.com/auth/cloud-platform',\n  });\n\n  // Get the credentials for the default project\n  const client = await auth.getClient();\n  const accessToken = await client.getAccessToken();\n\n  console.log('Successfully obtained access token using Application Default Credentials.');\n  console.log('Access Token:', accessToken.token);\n\n  // Example: Use the token to make an authenticated request\n  // (This is illustrative; actual API calls would use a client library or fetch with Authorization header)\n  if (accessToken.token) {\n    const url = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + accessToken.token;\n    try {\n      const response = await fetch(url);\n      const data = await response.json();\n      console.log('Token Info:', data);\n    } catch (fetchError) {\n      console.error('Failed to verify token:', fetchError);\n    }\n  } else {\n    console.warn(\"No access token found. Ensure ADC is configured correctly (e.g., GOOGLE_APPLICATION_CREDENTIALS set or running on GCP).\");\n  }\n}\n\nauthenticateWithADC().catch(console.error);\n","lang":"typescript","description":"Installs the library and authenticates using Application Default Credentials (ADC) to obtain and verify an access token."},"warnings":[{"fix":"Upgrade your Node.js environment to version 18 or a more recent LTS release (e.g., using nvm: `nvm install 18 && nvm use 18`).","message":"The library explicitly requires Node.js v18 or newer. Running on older versions will result in runtime errors or unexpected behavior.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"For new projects or modern Node.js environments, use ES Module `import` syntax (e.g., `import { Class } from 'pkg';`). Ensure your `package.json` specifies `\"type\": \"module\"` for ESM projects.","message":"While the library supports CommonJS, it is primarily designed for ES Modules. Using incorrect import syntax (e.g., `require` in an ES Module context) can lead to 'require is not defined' or `undefined` module exports.","severity":"gotcha","affected_versions":">=10.0.0"},{"fix":"Rely solely on the public API of `google-auth-library` for token management and generation. Avoid direct interaction with internal `gtoken` implementations.","message":"The `gtoken` dependency, previously exposed in some internal contexts, was internalized within the `google-auth-library` since v10.6.0. Direct access or manipulation of `gtoken` objects is no longer officially supported and may break.","severity":"breaking","affected_versions":">=10.6.0"},{"fix":"Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key file, run `gcloud auth application-default login`, or ensure your application is deployed on a Google Cloud environment that provides default credentials.","message":"Application Default Credentials (ADC) require proper environment configuration (e.g., `GOOGLE_APPLICATION_CREDENTIALS` environment variable, `gcloud` login, or running on GCP/GKE) to function automatically. Without it, authentication calls will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review and update custom proxy agent configurations to be compatible with the latest `http-proxy-agent` versions. Ensure any custom agent factories are correctly exporting constructors or objects as expected by updated dependencies.","message":"Updates to underlying HTTP proxy agents (e.g., `http-proxy-agent` updated to v7 in `teeny-request`, which is used by this library) may require adjustments if custom proxy configurations are used, potentially causing connection issues.","severity":"gotcha","affected_versions":">=10.6.2"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Upgrade your Node.js runtime to version 18 or higher. For example, using nvm: `nvm install 18 && nvm use 18`.","cause":"The installed version of `google-auth-library` requires Node.js v18 or newer.","error":"Error: Node.js v16.x.x is not supported."},{"fix":"If your project is ESM, ensure `\"type\": \"module\"` is set in `package.json` and use `import` statements. If CommonJS, verify no conflicting ESM configurations.","cause":"Attempting to use CommonJS `require()` syntax within an ES Module (ESM) context, or a general module import mismatch.","error":"TypeError: require is not a function"},{"fix":"Authenticate using `gcloud auth application-default login`, set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to a service account key file path, or ensure your application runs within a Google Cloud environment with associated service accounts.","cause":"Application Default Credentials (ADC) could not be automatically located or configured in the current environment.","error":"Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information."}],"ecosystem":"npm"}