Skip to main content

Crate node_auth

Crate node_auth 

Source
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 .npmrc and writes secrets to user-level ~/.npmrc by 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 .npmrc is not properly ignored.
  • Yarn Support: Detects and updates npmScopes authentication in .yarnrc.yml.
  • Bun Support: Discovers registries in bunfig.toml and optionally manages a local .env.local token 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.
npmrc
.npmrc configuration 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 (.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 .npmrc and .yarnrc.yml configuration files.
run_blocking
Executes authentication synchronously using a temporary Tokio runtime.