@robinpath/auth
Advanced tools
+95
| # @robinpath/auth | ||
| > API authentication helpers: Basic, Bearer, API key, HMAC signing, and password hashing | ||
|     | ||
| ## Why use this module? | ||
| The `auth` module lets you: | ||
| - Create a Basic authentication header from username and password | ||
| - Parse a Basic auth header to extract username and password | ||
| - Create a Bearer authentication header from a token | ||
| - Extract the token from a Bearer auth header | ||
| - Create an API key configuration for header or query parameter placement | ||
| All functions are callable directly from RobinPath scripts with a simple, consistent API. | ||
| ## Installation | ||
| ```bash | ||
| npm install @robinpath/auth | ||
| ``` | ||
| ## Quick Start | ||
| No credentials needed — start using it right away: | ||
| ```robinpath | ||
| auth.parseBasic "Basic dXNlcjpwYXNz" | ||
| ``` | ||
| ## Available Functions | ||
| | Function | Description | | ||
| |----------|-------------| | ||
| | `auth.basic` | Create a Basic authentication header from username and password | | ||
| | `auth.parseBasic` | Parse a Basic auth header to extract username and password | | ||
| | `auth.bearer` | Create a Bearer authentication header from a token | | ||
| | `auth.parseBearer` | Extract the token from a Bearer auth header | | ||
| | `auth.apiKey` | Create an API key configuration for header or query parameter placement | | ||
| | `auth.hmacSign` | Create an HMAC signature for a payload | | ||
| | `auth.hmacVerify` | Verify an HMAC signature using timing-safe comparison | | ||
| | `auth.generateApiKey` | Generate a cryptographically secure random API key | | ||
| | `auth.hashPassword` | Hash a password using PBKDF2 with a random salt | | ||
| | `auth.verifyPassword` | Verify a password against a PBKDF2 hash (timing-safe) | | ||
| | `auth.buildAuthHeader` | Build an Authorization header from a type and credentials | | ||
| | `auth.parseAuthHeader` | Parse any Authorization header into its scheme and credentials | | ||
| ## Examples | ||
| ### Parse a Basic auth header to extract username and password | ||
| ```robinpath | ||
| auth.parseBasic "Basic dXNlcjpwYXNz" | ||
| ``` | ||
| ### Create a Bearer authentication header from a token | ||
| ```robinpath | ||
| auth.bearer "eyJhbGciOi..." | ||
| ``` | ||
| ### Extract the token from a Bearer auth header | ||
| ```robinpath | ||
| auth.parseBearer "Bearer eyJhbGciOi..." | ||
| ``` | ||
| ## Integration with RobinPath | ||
| ```typescript | ||
| import { RobinPath } from "@wiredwp/robinpath"; | ||
| import Module from "@robinpath/auth"; | ||
| const rp = new RobinPath(); | ||
| rp.registerModule(Module.name, Module.functions); | ||
| rp.registerModuleMeta(Module.name, Module.functionMetadata); | ||
| const result = await rp.executeScript(` | ||
| auth.parseBasic "Basic dXNlcjpwYXNz" | ||
| `); | ||
| ``` | ||
| ## Full API Reference | ||
| See [MODULE.md](./MODULE.md) for complete documentation including all parameters, return types, error handling, and advanced examples. | ||
| ## Related Modules | ||
| - [`@robinpath/json`](../json) — JSON module for complementary functionality | ||
| ## License | ||
| MIT |
+25
-7
| { | ||
| "name": "@robinpath/auth", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "description": "API authentication helpers (Basic, Bearer, API key, HMAC) for RobinPath", | ||
| "publishConfig": { "access": "public" }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "type": "module", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" } }, | ||
| "files": ["dist"], | ||
| "scripts": { "build": "tsc", "test": "node --import tsx --test tests/*.test.ts" }, | ||
| "peerDependencies": { "@wiredwp/robinpath": ">=0.20.0" }, | ||
| "devDependencies": { "@wiredwp/robinpath": "^0.30.1", "tsx": "^4.19.0", "typescript": "^5.6.0" } | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "test": "node --import tsx --test tests/*.test.ts" | ||
| }, | ||
| "peerDependencies": { | ||
| "@wiredwp/robinpath": ">=0.20.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@wiredwp/robinpath": "^0.30.1", | ||
| "tsx": "^4.19.0", | ||
| "typescript": "^5.6.0" | ||
| } | ||
| } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
35245
9.49%10
11.11%0
-100%96
Infinity%1
Infinity%