Expand description
§node-auth
A fast, lightweight, standalone Rust CLI and library that authenticates JavaScript package managers (npm, yarn, pnpm, and Bun) to private Google Artifact Registry (GAR) npm repositories using Google Cloud Application Default Credentials (ADC).
§Overview
node-auth replicates and improves upon Google’s @google-cloud/artifact-registry-npm-tools
without requiring a JavaScript runtime or package manager to be installed beforehand.
§Key Features
- Automatic Credential Discovery: Searches for explicit tokens, Application Default Credentials (ADC),
and falls back to
gcloud auth print-access-token. - Credential Isolation: Reads registry endpoints from project-level
.npmrcand writes secrets to user-level~/.npmrcby default, preventing sensitive tokens from being checked into source control. - Git Safety Checks: When
--local-credentialis used, checks.gitignoreand emits warnings if.npmrcis not properly ignored. - Yarn Modern Support: Detects and updates
npmScopesauthentication in.yarnrc.yml. - Bun Support: Discovers registries in
bunfig.tomland optionally manages a local.env.localtoken reference.
The cli feature is enabled by default and provides both executables and the CLI modules.
Library consumers can disable it with default-features = false to omit CLI dependencies.
The example below requires Tokio with the macros and rt-multi-thread features in the
consuming application.
§Library Usage Example
use node_auth::{run, Options};
#[tokio::main]
async fn main() -> Result<(), node_auth::AuthError> {
let options = Options {
token: Some("custom-token".to_string()),
..Default::default()
};
run(&options).await?;
Ok(())
}Re-exports§
pub use error::AuthError;
Modules§
- auth
- Google Cloud credential retrieval and authentication handling.
- bunfig
- Bun (
bunfig.toml) registry discovery and local environment authentication. - cli
- Command-line argument parsing and CLI definitions for
node-auth. - error
- Error types for authentication and configuration failures.
- fs
- Path resolution and isolated, atomic configuration-file replacement.
- logger
- CLI-only logging and presentation. Library operations never initialize this logger.
- npmrc
.npmrcconfiguration parsing, formatting, and transformation.- registry
- Shared URL validation for npm and Yarn registries.
- token
- Access-token validation.
- vcs
- Git-backed inspection of local credential file safety.
- yarnrc
- Yarn Berry / Yarn Modern (
.yarnrc.yml) configuration management.
Structs§
- Options
- Configuration options for configuring Node authentication.
Enums§
- RunOutcome
- Useful result of a library authentication run, with presentation left to callers.
Functions§
- run
- Executes authentication and updates
.npmrcand.yarnrc.ymlconfiguration files. - run_
blocking - Executes authentication synchronously using a temporary Tokio runtime.