@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/.agents/config.toml +2 -0
- package/.agents/skills/carecard-workspace-standards/SKILL.md +401 -0
- package/.agents/skills/carecard-workspace-standards/agents/openai.yaml +4 -0
- package/.agents/skills/github-pr-create-update/SKILL.md +188 -0
- package/.agents/skills/github-pr-create-update/agents/openai.yaml +5 -0
- package/.agents/skills/github-pr-merge-cleanup/SKILL.md +175 -0
- package/.agents/skills/github-pr-merge-cleanup/agents/openai.yaml +5 -0
- package/.agents/skills/pkg-auth-util-auth-crypto-library/SKILL.md +239 -0
- package/.agents/skills/pkg-auth-util-auth-crypto-library/agents/openai.yaml +4 -0
- package/.agents/skills/software-design-patterns-and-clean-code/SKILL.md +73 -0
- package/.codex/config.toml +2 -0
- package/.prettierrc.js +12 -0
- package/eslint.config.mjs +14 -0
- package/index.d.ts +197 -151
- package/index.js +29 -28
- package/lib/jwtUtilAuth.js +152 -86
- package/lib/keyGen.js +18 -22
- package/lib/pwdUtilAuth.js +25 -25
- package/lib/stringUtilAuth.js +43 -49
- package/package.json +23 -11
- package/readme.md +37 -5
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 {
|
|
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 =
|
|
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 =
|
|
38
|
+
const isValid = jwtVerifySignedToken(token, publicKey);
|
|
39
39
|
|
|
40
40
|
// Get header and payload from a JWT
|
|
41
|
-
const { header: decodedHeader, payload: decodedPayload } =
|
|
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 =
|
|
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.
|