@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 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** token storage, session restoration, sign-up/sign-in/sign-out
10
- - **React hooks** `useAuth()`, `useCurrentUser()`, `useAuthStatus()` for reactive auth state
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
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
- | `TokenStore` | Client-side token persistence |
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` | Sign challenge with device key |
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/validation |
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
- | `BuiltInProvider` | Adapter wrapping routes |
130
- | `hashPassword` / `verifyPassword` | PBKDF2 password hashing |
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
- - Constant-time signature comparison (prevents timing attacks)
138
- - Device keys use ECDSA P-256 with non-extractable private keys
139
- - Refresh token rotation on each use
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 Server
146
- ┌──────────────────┐ ┌──────────────────┐
147
- AuthClient │ BuiltInAuthRoutes│
148
- ├─ TokenStore ──── HTTP ────> │ ├─ UserStore
149
- └─ AuthState │ ├─ TokenManager
150
- └─ PasswordHash
151
- React Hooks
152
- ├─ useAuth SyncAuthProvider
153
- ├─ useCurrentUser└─ authenticate()
154
- └─ useAuthStatus └──────────────────┘
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