@nabhiraj/nab-auth 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +33 -74
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,12 +1,23 @@
1
- # Nab Authentication
1
+ # nab-auth
2
2
 
3
- Configurable authentication for Express applications using MongoDB, Argon2id,
4
- and RS256 JWTs. It includes registration, password login, refresh tokens,
5
- roles, optional registration verification, and optional two-factor
6
- authentication.
3
+ [![license](https://img.shields.io/npm/l/@nabhiraj/nab-auth.svg)](LICENSE)
4
+
5
+ Configurable authentication for Express and MongoDB. `nab-auth` provides
6
+ Argon2id password hashing, RS256 JWTs, refresh-token rotation, roles,
7
+ registration verification, and optional two-factor authentication.
7
8
 
8
9
  The library does not load environment variables or send email/SMS itself. The
9
- application using it owns both configuration and code delivery.
10
+ host application owns configuration and code delivery.
11
+
12
+ ## Features
13
+
14
+ - Email/password registration and login with Argon2id password hashes
15
+ - Short-lived RS256 access tokens and rotating refresh-token cookies
16
+ - Public-key rotation using JWT `kid` headers
17
+ - Role claims and administrator-protected role management
18
+ - Optional registration-code verification and two-factor authentication
19
+ - MongoDB/Atlas storage with unique and TTL indexes created automatically
20
+ - Verifier-only mode for services that only need to validate access tokens
10
21
 
11
22
  ## Requirements
12
23
 
@@ -21,17 +32,14 @@ unusual platforms may need standard Node.js native build tools.
21
32
  ## Installation
22
33
 
23
34
  ```bash
24
- npm install @nabhiraj/nab-authentication express
35
+ npm install @nabhiraj/nab-auth express
25
36
  ```
26
37
 
27
- Replace `@nabhiraj` if you publish the package under another npm scope.
28
-
29
38
  ## Quick start
30
39
 
31
40
  ```js
32
- import "dotenv/config";
33
41
  import express from "express";
34
- import { createAuthenticationLibrary } from "@nabhiraj/nab-authentication";
42
+ import { createAuthenticationLibrary } from "@nabhiraj/nab-auth";
35
43
 
36
44
  const app = express();
37
45
  app.use(express.json());
@@ -78,14 +86,18 @@ await auth.connectToDatabase();
78
86
  app.listen(3000);
79
87
  ```
80
88
 
81
- ## Public API
89
+ `sendEmail` is an application function you provide. Configure a code-delivery
90
+ callback only when registration verification or two-factor authentication is
91
+ enabled.
92
+
93
+ ## Core API
82
94
 
83
95
  ```js
84
96
  import {
85
97
  createAuthenticationLibrary,
86
98
  createFileJwtKeyProvider,
87
99
  defaultAuthConfig
88
- } from "@nabhiraj/nab-authentication";
100
+ } from "@nabhiraj/nab-auth";
89
101
  ```
90
102
 
91
103
  `createAuthenticationLibrary(config)` creates isolated state: its MongoDB
@@ -268,7 +280,7 @@ const auth = createAuthenticationLibrary({
268
280
 
269
281
  When `jwt.keyProvider` is supplied, the file paths are not used.
270
282
 
271
- ## Routes
283
+ ## HTTP API
272
284
 
273
285
  Assume the router is mounted at `/auth`.
274
286
 
@@ -288,7 +300,7 @@ Access tokens include the application payload and access-token metadata.
288
300
  Refresh tokens contain only the subject and required token metadata, not the
289
301
  complete application payload.
290
302
 
291
- ## MongoDB documents
303
+ ## Data stored in MongoDB
292
304
 
293
305
  The users collection contains documents like:
294
306
 
@@ -328,7 +340,7 @@ app.get("/api/business-data", auth.requireJwt, (req, res) => {
328
340
  app.use(auth.jwtErrorHandler);
329
341
  ```
330
342
 
331
- ## Security notes
343
+ ## Production checklist
332
344
 
333
345
  - Use HTTPS and `refreshCookie.secure: true` in production.
334
346
  - Set `codeDelivery.allowCodeInResponseWithoutSender: false` in production.
@@ -339,65 +351,12 @@ app.use(auth.jwtErrorHandler);
339
351
  - Configure CORS and cookie `sameSite` settings for your frontend topology.
340
352
  - Retain old public keys until tokens signed by them expire.
341
353
 
342
- ## Development and testing
343
-
344
- ```bash
345
- npm install
346
- npm test
347
- ```
348
-
349
- The demo servers in `src/server.js` and `src/server2.js` are intentionally not
350
- published in the npm package. If you run those examples from this repository,
351
- install and load their example-only dependencies separately.
352
-
353
- Run automated tests:
354
-
355
- ```bash
356
- npm test
357
- ```
358
-
359
- Before publishing, inspect the exact package contents:
360
-
361
- ```bash
362
- npm run pack-check
363
- ```
364
-
365
- Test the generated archive from a separate consumer project:
366
-
367
- ```bash
368
- npm pack
369
- mkdir ../auth-package-consumer
370
- cd ../auth-package-consumer
371
- npm init -y
372
- npm install ../nab_authenticate/nabhiraj-nab-authentication-0.1.0.tgz express
373
- ```
374
-
375
- Create a small Express app there and verify import, database connection,
376
- router creation, and JWT verification.
377
-
378
- ## Publishing
379
-
380
- 1. Create an npm account and check that the package name is available.
381
- 2. Run `npm test` and `npm run pack-check`.
382
- 3. Confirm that `.env`, key files, and demo applications are not in the pack
383
- listing.
384
- 4. Authenticate with `npm login`.
385
- 5. Publish:
386
-
387
- ```bash
388
- npm publish
389
- ```
390
-
391
- For later releases:
392
-
393
- ```bash
394
- npm version patch # 0.1.0 -> 0.1.1
395
- npm version minor # 0.1.0 -> 0.2.0
396
- npm version major # 0.1.0 -> 1.0.0
397
- npm publish
398
- ```
354
+ ## Support and contributing
399
355
 
400
- The package is pre-1.0.0, so document any breaking public API changes.
356
+ Source code, bug reports, and feature requests are managed in the
357
+ [GitLab project](https://gitlab.com/platforms8851042/nab_authenticate).
358
+ Please use [GitLab Issues](https://gitlab.com/platforms8851042/nab_authenticate/-/issues)
359
+ for reproducible bugs and feature proposals.
401
360
 
402
361
  ## License
403
362
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nabhiraj/nab-auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Configurable Express, MongoDB, JWT, registration verification, and 2FA authentication library",
5
5
  "type": "module",
6
6
  "main": "./src/authenticationLogic/index.js",