@korajs/auth 0.1.0 → 0.3.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.
- package/README.md +69 -30
- package/dist/chunk-FSU4SK32.js +786 -0
- package/dist/chunk-FSU4SK32.js.map +1 -0
- package/dist/chunk-HOZXDR6Y.js +52 -0
- package/dist/chunk-HOZXDR6Y.js.map +1 -0
- package/dist/index.cjs +1546 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +708 -5
- package/dist/index.d.ts +708 -5
- package/dist/index.js +934 -8
- package/dist/index.js.map +1 -1
- package/dist/{device-identity-DiwdLsUB.d.cts → operation-encryptor-DRmKNWpF.d.cts} +148 -2
- package/dist/{device-identity-DiwdLsUB.d.ts → operation-encryptor-DRmKNWpF.d.ts} +148 -2
- package/dist/{auth-client-CrDNuh10.d.cts → org-client-BVTLKcIk.d.cts} +177 -3
- package/dist/{auth-client-CrDNuh10.d.ts → org-client-BVTLKcIk.d.ts} +177 -3
- package/dist/password-hash-HDH6VQCQ.js +9 -0
- package/dist/password-hash-HDH6VQCQ.js.map +1 -0
- package/dist/react.cjs +183 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +107 -2
- package/dist/react.d.ts +107 -2
- package/dist/react.js +186 -1
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +5354 -233
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +3304 -97
- package/dist/server.d.ts +3304 -97
- package/dist/server.js +4653 -92
- package/dist/server.js.map +1 -1
- package/package.json +15 -6
- package/dist/chunk-L554ZDPY.js +0 -174
- package/dist/chunk-L554ZDPY.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,11 +6,17 @@ Offline-first authentication for Kora.js applications.
|
|
|
6
6
|
|
|
7
7
|
`@korajs/auth` provides a complete authentication system designed for offline-first applications. It includes:
|
|
8
8
|
|
|
9
|
-
- **Client-side auth management**
|
|
10
|
-
- **React hooks**
|
|
11
|
-
- **Server-side auth routes**
|
|
12
|
-
- **Device identity**
|
|
13
|
-
- **Token management**
|
|
9
|
+
- **Client-side auth management** -- token storage, session restoration, sign-up/sign-in/sign-out
|
|
10
|
+
- **React hooks** -- `useAuth()`, `useCurrentUser()`, `useAuthStatus()`, `useOrg()`, `usePermission()`
|
|
11
|
+
- **Server-side auth routes** -- email/password authentication with JWT tokens
|
|
12
|
+
- **Device identity** -- ECDSA P-256 key pairs for proof-of-possession
|
|
13
|
+
- **Token management** -- access/refresh token lifecycle with rotation and revocation detection
|
|
14
|
+
- **Session management** -- server-side sessions with idle timeout, max limits, and MFA awareness
|
|
15
|
+
- **Multi-factor authentication** -- TOTP (authenticator apps) with recovery codes
|
|
16
|
+
- **Organizations and RBAC** -- multi-tenant orgs with role hierarchy and permission checks
|
|
17
|
+
- **Passkeys (WebAuthn)** -- passwordless authentication with platform authenticators
|
|
18
|
+
- **Encrypted token storage** -- AES-256-GCM encryption for sensitive environments
|
|
19
|
+
- **End-to-end encryption** -- encrypt operation data before sync with `OperationEncryptor`
|
|
14
20
|
|
|
15
21
|
## Installation
|
|
16
22
|
|
|
@@ -102,55 +108,88 @@ const syncServer = new KoraSyncServer({
|
|
|
102
108
|
|
|
103
109
|
| Export | Description |
|
|
104
110
|
|--------|-------------|
|
|
105
|
-
| `AuthClient` | Client-side auth manager |
|
|
106
|
-
| `
|
|
111
|
+
| `AuthClient` | Client-side auth manager (sign-up, sign-in, sign-out, token refresh) |
|
|
112
|
+
| `OrgClient` | Client-side organization management |
|
|
113
|
+
| `TokenStore` | Client-side token persistence (localStorage) |
|
|
114
|
+
| `EncryptedTokenStore` | AES-256-GCM encrypted token persistence |
|
|
107
115
|
| `generateDeviceKeyPair` | ECDSA P-256 key pair generation |
|
|
108
116
|
| `exportPublicKeyJwk` | Export public key as JWK |
|
|
109
|
-
| `signChallenge`
|
|
110
|
-
| `verifyChallenge` | Verify challenge signature |
|
|
117
|
+
| `signChallenge` / `verifyChallenge` | Device proof-of-possession |
|
|
111
118
|
| `computePublicKeyThumbprint` | RFC 7638 JWK thumbprint |
|
|
119
|
+
| `isPasskeySupported` | Check WebAuthn availability |
|
|
120
|
+
| `createPasskeyCredential` | Register a new passkey |
|
|
121
|
+
| `authenticateWithPasskey` | Sign in with a passkey |
|
|
122
|
+
| `encryptData` / `decryptData` | AES-256-GCM data encryption |
|
|
123
|
+
| `OperationEncryptor` | E2E encryption for sync operations |
|
|
124
|
+
| `AutoLockManager` | Auto-lock encryption keys after idle timeout |
|
|
112
125
|
|
|
113
126
|
### `@korajs/auth/react`
|
|
114
127
|
|
|
115
128
|
| Export | Description |
|
|
116
129
|
|--------|-------------|
|
|
117
130
|
| `AuthProvider` | React context provider |
|
|
118
|
-
| `useAuth` | Full auth hook (user, methods, error) |
|
|
131
|
+
| `useAuth` | Full auth hook (user, methods, error, loading) |
|
|
119
132
|
| `useCurrentUser` | Lightweight current user hook |
|
|
120
133
|
| `useAuthStatus` | Auth status for route guards |
|
|
134
|
+
| `useOrg` | Organization context and switching |
|
|
135
|
+
| `useOrgMembers` | Org member listing |
|
|
136
|
+
| `usePermission` | RBAC permission check hook |
|
|
121
137
|
|
|
122
138
|
### `@korajs/auth/server`
|
|
123
139
|
|
|
124
140
|
| Export | Description |
|
|
125
141
|
|--------|-------------|
|
|
126
|
-
| `BuiltInAuthRoutes` | HTTP route handlers |
|
|
127
|
-
| `TokenManager` | JWT issuing
|
|
142
|
+
| `BuiltInAuthRoutes` | HTTP route handlers for all auth operations |
|
|
143
|
+
| `TokenManager` | JWT issuing, validation, refresh rotation, revocation |
|
|
128
144
|
| `InMemoryUserStore` | Dev/test user store |
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
145
|
+
| `InMemoryTokenRevocationStore` | Dev/test token revocation store |
|
|
146
|
+
| `SessionManager` / `InMemorySessionStore` | Server-side session management |
|
|
147
|
+
| `TotpManager` / `InMemoryTotpStore` | TOTP MFA with recovery codes |
|
|
148
|
+
| `OrgRoutes` / `InMemoryOrgStore` | Organization CRUD, invitations, member management |
|
|
149
|
+
| `RbacEngine` / `defineRoles` | Role-based access control with permission hierarchy |
|
|
150
|
+
| `OrgScopeResolver` | Generate sync scope filters from org membership |
|
|
151
|
+
| `EmailVerificationManager` | Email verification token flow |
|
|
152
|
+
| `PasswordResetManager` | Password reset and change flows |
|
|
153
|
+
| `hashPassword` / `verifyPassword` | PBKDF2-SHA512 password hashing |
|
|
131
154
|
| `encodeJwt` / `verifyJwt` | Low-level JWT operations |
|
|
132
155
|
|
|
133
156
|
## Security
|
|
134
157
|
|
|
135
158
|
- Passwords hashed with PBKDF2-SHA512 (600,000 iterations, 32-byte salt)
|
|
136
|
-
- JWT tokens signed with HMAC-SHA256
|
|
137
|
-
-
|
|
138
|
-
- Device keys use ECDSA P-256 with non-extractable private keys
|
|
139
|
-
-
|
|
140
|
-
- Access tokens expire in 15 minutes (configurable)
|
|
159
|
+
- JWT tokens signed with HMAC-SHA256 with constant-time comparison
|
|
160
|
+
- Refresh token rotation with replay detection and device-level revocation
|
|
161
|
+
- Device keys use ECDSA P-256 with non-extractable private keys (Web Crypto)
|
|
162
|
+
- TOTP uses SHA-1 HMAC per RFC 6238 with 30-second time steps
|
|
163
|
+
- Access tokens expire in 15 minutes (configurable), refresh tokens in 7 days
|
|
164
|
+
- Session idle timeout with sliding window and configurable max concurrent sessions
|
|
165
|
+
- Passkeys use WebAuthn L2 with platform authenticator support
|
|
166
|
+
- Encrypted token store uses AES-256-GCM with PBKDF2-derived keys
|
|
141
167
|
|
|
142
168
|
## Architecture
|
|
143
169
|
|
|
144
170
|
```
|
|
145
|
-
Client
|
|
146
|
-
|
|
147
|
-
│
|
|
148
|
-
│
|
|
149
|
-
│
|
|
150
|
-
│
|
|
151
|
-
│
|
|
152
|
-
│
|
|
153
|
-
│
|
|
154
|
-
│
|
|
155
|
-
|
|
171
|
+
Client Server
|
|
172
|
+
┌────────────────────┐ ┌────────────────────────┐
|
|
173
|
+
│ AuthClient │ │ BuiltInAuthRoutes │
|
|
174
|
+
│ ├─ TokenStore │ │ ├─ UserStore │
|
|
175
|
+
│ ├─ EncryptedStore │ ── HTTP ───> │ ├─ TokenManager │
|
|
176
|
+
│ ├─ OrgClient │ │ ├─ SessionManager │
|
|
177
|
+
│ └─ DeviceKeyStore │ │ ├─ TotpManager │
|
|
178
|
+
│ │ │ ├─ OrgRoutes │
|
|
179
|
+
│ React Hooks │ │ ├─ RbacEngine │
|
|
180
|
+
│ ├─ useAuth │ │ └─ PasswordResetMgr │
|
|
181
|
+
│ ├─ useOrg │ │ │
|
|
182
|
+
│ └─ usePermission │ │ SyncAuthProvider │
|
|
183
|
+
│ │ │ └─ authenticate() │
|
|
184
|
+
│ Passkeys │ │ └─ OrgScopeResolver │
|
|
185
|
+
│ └─ WebAuthn API │ └────────────────────────┘
|
|
186
|
+
└────────────────────┘
|
|
156
187
|
```
|
|
188
|
+
|
|
189
|
+
## Documentation
|
|
190
|
+
|
|
191
|
+
See the [Authentication Guide](https://ehoneahobed.github.io/kora/guide/authentication) and [Auth API Reference](https://ehoneahobed.github.io/kora/api/auth) for complete documentation.
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|