Registry / gcp / gapitoken

gapitoken

JSON →
library0.1.5jsnpmunverified

gapitoken is a Node.js module designed for Google API service account authorization, specifically implementing the Server-to-Server flow using JSON Web Tokens (JWT). The package, currently at version 0.1.5 and last published over a decade ago, facilitates obtaining access tokens by providing service account credentials (email address and private key). It allows the private key to be supplied either as a file path or directly as a string. Historically, it provided a direct method for generating Google-specific JWTs. However, this library is considered abandoned. The current stable approach for Google API authentication in Node.js relies on the official `@google-cloud/google-auth-library` or `googleapis` libraries, which offer more robust, actively maintained, and officially supported authentication methods like Application Default Credentials (ADC), OAuth 2.0, and integrated JWT clients that handle credential management, token refreshing, and a broader range of authentication flows. These modern alternatives provide better security practices, up-to-date compatibility, and ongoing support compared to this unmaintained package.

npm install gapitoken
INSTALL
IMPORT
SIG · GAPITOKEN
G
gapitoken
gcpjavascriptv0.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GAPI
const GAPI = require('gapitoken');
import GAPI from 'gapitoken';
This package is a CommonJS module and must be imported using `require()`.
GAPIConstructor
const GAPI = require('gapitoken'); const gapi = new GAPI({...});
import { GAPI } from 'gapitoken';
The primary export is a constructor function for GAPI instances; named ESM imports are not supported.

This quickstart demonstrates how to initialize `gapitoken` with a service account email, desired scopes, and a private key string (from environment variables), then obtain an access token for Google API authorization.

const GAPI = require('gapitoken'); const SERVICE_ACCOUNT_EMAIL = process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL ?? ''; const SCOPES = process.env.GOOGLE_API_SCOPES ?? 'https://www.googleapis.com/auth/cloud-platform'; const PRIVATE_KEY_STRING = process.env.GOOGLE_PRIVATE_KEY_STRING ?? ''; // Ensure environment variables are set if (!SERVICE_ACCOUNT_EMAIL || !SCOPES || !PRIVATE_KEY_STRING) { console.error('Missing required environment variables: GOOGLE_SERVICE_ACCOUNT_EMAIL, GOOGLE_API_SCOPES, GOOGLE_PRIVATE_KEY_STRING'); process.exit(1); } new GAPI({ iss: SERVICE_ACCOUNT_EMAIL, scope: SCOPES, key: PRIVATE_KEY_STRING }, function(err) { if (err) { console.error('Failed to initialize GAPI:', err); return; } this.getToken(function(err, token) { if (err) { console.error('Failed to get token:', err); return; } console.log('Successfully obtained token:', token); }); });
Debug
Known issues
breakingThe `gapitoken` package is no longer maintained. It has not received updates for over 10 years, meaning it lacks bug fixes, security patches, or compatibility updates for newer Node.js versions or evolving Google API authentication standards. Continued use may expose applications to security vulnerabilities or compatibility issues.
fix
Migrate to Google's officially supported `google-auth-library` (e.g., `npm install google-auth-library`) for modern, secure, and maintained service account authentication. This library provides Application Default Credentials (ADC), OAuth2, and JWT clients.
affects: >=0.1.5
gotchaThe README's suggested method for converting `.p12` keys to `.pem` format involves several `openssl` commands, including removing the passphrase. This process is complex and can be a source of errors. Improper handling of private keys, especially removing passphrases from files, can introduce security risks if the key file is compromised.
fix
Avoid manual `.p12` to `.pem` conversion where possible. Modern Google Cloud authentication typically uses a JSON key file downloaded directly from the Google Cloud Console, which is consumed by the `google-auth-library` and generally does not require `openssl` manipulation for basic setup. When using JSON key files, store them securely and leverage environment variables like `GOOGLE_APPLICATION_CREDENTIALS`.
affects: >=0.1.5
deprecatedEmbedding raw private key strings directly in application code or configuration files is an insecure practice. The package also allows specifying a `keyFile` path, which still requires careful secret management.
fix
Utilize environment variables (e.g., `process.env.GOOGLE_PRIVATE_KEY`) or dedicated secret management services (like Google Secret Manager, AWS Secrets Manager, or HashiCorp Vault) to store and retrieve sensitive private key information. When using `google-auth-library`, rely on Application Default Credentials and the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to a service account JSON file.
affects: >=0.1.5
Errors
Common errors & fixes
Error: Invalid Credentials
When using the obtained token with Google APIs, the 'Authorization' header often requires a 'Bearer ' prefix, which `gapitoken` itself does not automatically add to the raw token it provides.
fix
Ensure that any HTTP requests made with the token include `Authorization: Bearer <your_token>` in the headers. For example, `headers: { 'Authorization': 'Bearer ' + token }`.
Error: Error reading private key.pem
The `keyFile` path is incorrect, the file is unreadable due to permissions, or the `.pem` file is not in the expected format (e.g., still passphrase-protected, or corrupted).
fix
Verify the `keyFile` path, check file system permissions for the Node.js process, and ensure the `.pem` file was correctly generated from the `.p12` file, with its passphrase removed using `openssl rsa -in key.pem -out key.pem` as per the original README instructions.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
40 hits · last 30 days
node
34
OpenAI (training)
1
Resources
gapitoken — npm install gapitoken · libregistry