@carecard/auth-util 3.1.13 → 3.1.16

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.
package/readme.md CHANGED
@@ -24,21 +24,39 @@ npm install @carecard/auth-util
24
24
  ### JWT Utilities (`jwtUtilAuth`)
25
25
 
26
26
  ```javascript
27
- const { jwtUtilAuth } = require('@carecard/auth-util');
27
+ const { jwtCreateSignedToken, jwtGetHeaderPayload, jwtVerifySignedToken } = require('@carecard/auth-util');
28
28
 
29
29
  const header = { alg: 'EdDSA', typ: 'JWT' };
30
30
  const payload = { sub: '1234567890', name: 'John Doe' };
31
31
  const privateKey = '...'; // Your private PEM key
32
32
 
33
33
  // Create a signed JWT
34
- const token = jwtUtilAuth.createSignedJwtFromObject(header, payload, privateKey);
34
+ const token = jwtCreateSignedToken(header, payload, privateKey);
35
35
 
36
36
  // Verify a JWT signature
37
37
  const publicKey = '...'; // Your public PEM key
38
- const isValid = jwtUtilAuth.verifyJwtSignature(token, publicKey);
38
+ const isValid = jwtVerifySignedToken(token, publicKey);
39
39
 
40
40
  // Get header and payload from a JWT
41
- const { header: decodedHeader, payload: decodedPayload } = jwtUtilAuth.getHeaderPayloadFromJwt(token);
41
+ const { header: decodedHeader, payload: decodedPayload } = jwtGetHeaderPayload(token);
42
+ ```
43
+
44
+ ### Service-To-Service JWT Creation
45
+
46
+ ```javascript
47
+ const { jwtCreateServiceAuthorizationHeader, jwtCreateServiceToken } = require('@carecard/auth-util');
48
+
49
+ const token = jwtCreateServiceToken({
50
+ issuer: 'ms-institutions',
51
+ audience: 'ms-auth',
52
+ privateKey: institutionsPrivateKey,
53
+ });
54
+
55
+ const authorization = jwtCreateServiceAuthorizationHeader({
56
+ issuer: 'ms-institutions',
57
+ audience: 'ms-auth',
58
+ privateKey: institutionsPrivateKey,
59
+ });
42
60
  ```
43
61
 
44
62
  ### Password Utilities (`pwdUtilAuth`)
@@ -55,7 +73,7 @@ const hash = pwdUtilAuth.createPasswordHashWithRandomSalt(password, secret, algo
55
73
  // Resulting format: $1$base64(algorithm)$base64(hash)$base64(salt)$
56
74
 
57
75
  // Verify a password against a saved hash
58
- const isCorrect = (pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt(password, hash, secret) === hash);
76
+ const isCorrect = pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt(password, hash, secret) === hash;
59
77
  ```
60
78
 
61
79
  ### Key Generation
@@ -82,6 +100,19 @@ const urlSafe = stringUtilAuth.makeStringUrlSafe('a+b/c==');
82
100
  // Result: a-b_c
83
101
  ```
84
102
 
103
+ ## CareCard Auth Contract
104
+
105
+ `ms-auth` issues CareCard user JWTs and now enforces its own auth tables with
106
+ forced PostgreSQL RLS. This package should preserve JWT claim values exactly
107
+ when creating or verifying tokens; a payload containing `roles: ["ad"]` is the
108
+ auth-service super-admin signal. Do not add helpers that hide, rename, or drop
109
+ the `roles` array, and do not add database bypass behavior to this package.
110
+
111
+ Docs that mention `ms-auth` controller internals should use concise action
112
+ names such as `loginUser`, `registerUser`, `getUserDetail`, and `renewJwt`.
113
+ Access level is conveyed by route middleware and endpoint placement, not by
114
+ `public`/`protected`/`admin`/`Handler` suffixes.
115
+
85
116
  ## Testing
86
117
 
87
118
  Run tests using:
@@ -99,6 +130,7 @@ npm run test:types
99
130
  ## Architecture
100
131
 
101
132
  The package is organized into several modules:
133
+
102
134
  - `jwtUtilAuth`: Manages the JWT lifecycle.
103
135
  - `pwdUtilAuth`: Handles password hashing and verification.
104
136
  - `keyGen`: Utility for generating cryptographic keys.