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 Node package managers (npm, yarn, and pnpm) 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 Node, npm, or pnpm to be installed or configured 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: When --local-credential is used, checks .gitignore and emits warnings if .npmrc is not properly ignored.
  • Yarn Modern Support: Detects and updates npmScopes authentication in .yarnrc.yml.

§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.
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
.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 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 .npmrc and .yarnrc.yml configuration files.