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: Reports Git ignore status when local credentials are requested,
allowing callers to warn when
.npmrcis not properly ignored. - Yarn 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 the interactive CLIs and CLI modules.
The token-only executable also builds without this feature.
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.
- npmrc
.npmrcconfiguration parsing, formatting, and transformation.- pnpm
- Dynamic pnpm authentication in the trusted, pnpm-specific user auth file.
- registry
- Shared URL validation for npm and Yarn registries.
- token
- Access-token validation.
- vcs
- Git-backed inspection of local credential file safety.
- yarnrc
- Yarn (
.yarnrc.yml) configuration management.
Structs§
- Options
- Configuration options for configuring Node authentication.
Enums§
- RunOutcome
- Result of a library authentication run.
Functions§
- run
- Executes authentication and updates
.npmrcand.yarnrc.ymlconfiguration files. - run_
blocking - Executes authentication synchronously using a temporary Tokio runtime.