@korajs/auth 1.0.0-beta.12 → 1.0.0-beta.13
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 +52 -47
- package/dist/{create-org-session-RsDj9cl4.d.cts → create-org-session-ChFdulEM.d.cts} +211 -17
- package/dist/{create-org-session-RsDj9cl4.d.ts → create-org-session-ChFdulEM.d.ts} +211 -17
- package/dist/index.cjs +645 -150
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +644 -150
- package/dist/index.js.map +1 -1
- package/dist/{operation-encryptor-DRmKNWpF.d.cts → operation-encryptor-DDdlb9bm.d.cts} +16 -0
- package/dist/{operation-encryptor-DRmKNWpF.d.ts → operation-encryptor-DDdlb9bm.d.ts} +16 -0
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/server.cjs +2852 -1675
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +779 -168
- package/dist/server.d.ts +779 -168
- package/dist/server.js +2831 -1665
- package/dist/server.js.map +1 -1
- package/dist/svelte.cjs +2 -2
- package/dist/svelte.cjs.map +1 -1
- package/dist/svelte.d.cts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +2 -2
- package/dist/svelte.js.map +1 -1
- package/dist/vue.d.cts +1 -1
- package/dist/vue.d.ts +1 -1
- package/package.json +7 -7
- package/src/admin/admin-api.ts +327 -0
- package/src/admin/audit-log.ts +324 -0
- package/src/admin/webhooks.ts +576 -0
- package/src/bindings/create-auth-session.ts +184 -0
- package/src/bindings/create-org-session.ts +130 -0
- package/src/client/auth-client.ts +1592 -0
- package/src/client/auth-sync.ts +213 -0
- package/src/client/device-session.ts +104 -0
- package/src/client/org-client.ts +399 -0
- package/src/client/quickstart.ts +108 -0
- package/src/client/storage.ts +94 -0
- package/src/device/device-identity.ts +330 -0
- package/src/device/device-store.ts +379 -0
- package/src/encryption/auto-lock.ts +170 -0
- package/src/encryption/database-encryption.ts +265 -0
- package/src/encryption/key-derivation.ts +149 -0
- package/src/encryption/operation-encryptor.ts +361 -0
- package/src/index.ts +132 -0
- package/src/mfa/totp.ts +826 -0
- package/src/org/org-routes.ts +758 -0
- package/src/org/org-store.ts +490 -0
- package/src/org/org-types.ts +230 -0
- package/src/passkey/passkey-client.ts +597 -0
- package/src/passkey/passkey-server.ts +779 -0
- package/src/postgres/ensure-schema.ts +65 -0
- package/src/provider/adapter.ts +246 -0
- package/src/provider/built-in/auth-routes.ts +1313 -0
- package/src/provider/built-in/email-verification.ts +303 -0
- package/src/provider/built-in/password-hash.ts +118 -0
- package/src/provider/built-in/password-reset.ts +416 -0
- package/src/provider/built-in/postgres-user-store.ts +328 -0
- package/src/provider/built-in/quickstart-server.ts +760 -0
- package/src/provider/built-in/sqlite-user-store.ts +322 -0
- package/src/provider/built-in/sync-scopes.ts +85 -0
- package/src/provider/built-in/user-store.ts +465 -0
- package/src/provider/external/clerk-adapter.ts +157 -0
- package/src/provider/external/external-jwt-provider.ts +491 -0
- package/src/provider/external/supabase-adapter.ts +163 -0
- package/src/provider/oauth/linked-identity-store.ts +108 -0
- package/src/provider/oauth/oauth-flow.ts +550 -0
- package/src/provider/oauth/oauth-types.ts +184 -0
- package/src/provider/oauth/postgres-oauth-store.ts +296 -0
- package/src/provider/oauth/sqlite-oauth-store.ts +272 -0
- package/src/rbac/rbac-engine.ts +323 -0
- package/src/rbac/rbac-types.ts +210 -0
- package/src/rbac/scope-resolver.ts +140 -0
- package/src/react/AuthProvider.tsx +97 -0
- package/src/react/OrgProvider.tsx +41 -0
- package/src/react/auth-context.ts +26 -0
- package/src/react/hooks.ts +110 -0
- package/src/react/org-hooks.ts +214 -0
- package/src/react.ts +26 -0
- package/src/server.ts +334 -0
- package/src/session/session.ts +401 -0
- package/src/svelte/auth-context.ts +50 -0
- package/src/svelte/org-context.ts +32 -0
- package/src/svelte/org-hooks.ts +201 -0
- package/src/svelte/use-auth.ts +115 -0
- package/src/svelte.ts +25 -0
- package/src/tokens/encrypted-token-store.ts +360 -0
- package/src/tokens/jwt.ts +236 -0
- package/src/tokens/postgres-token-revocation-store.ts +140 -0
- package/src/tokens/sqlite-token-revocation-store.ts +121 -0
- package/src/tokens/token-manager.ts +821 -0
- package/src/tokens/token-store.ts +192 -0
- package/src/types.ts +394 -0
- package/src/vue/auth-context.ts +10 -0
- package/src/vue/auth-provider-types.ts +5 -0
- package/src/vue/auth-provider.ts +76 -0
- package/src/vue/org-hooks.ts +193 -0
- package/src/vue/org-provider.ts +49 -0
- package/src/vue/use-auth.ts +139 -0
- package/src/vue.ts +10 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState } from './create-org-session-
|
|
2
|
-
export {
|
|
1
|
+
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState, f as AuthClientSession } from './create-org-session-ChFdulEM.cjs';
|
|
2
|
+
export { g as AuthDeviceIdentity, h as AuthDeviceIdentityError, i as AuthError, j as AuthSession, k as AuthSessionSnapshot, l as AuthSessionStatus, m as AuthTokenStorageOptions, n as AuthUser, C as ClientInvitation, o as ClientMembership, p as ClientOrganization, q as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, r as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, M as MfaRequiredError, O as OAuthAuthorizationOptions, s as OAuthAuthorizationResult, t as OAuthCallbackParams, u as OrgClient, v as OrgClientConfig, w as OrgClientError, x as OrgSession, y as OrgSnapshot, P as PersistentDeviceIdentityOptions, z as checkOrgPermission, B as createAuthSession, E as createAuthTokenStorage, F as createDeviceKeyStore, G as createMemoryAuthTokenStorage, H as createOrgSession, J as createPersistentDeviceIdentity, K as createWebStorageAuthTokenStorage } from './create-org-session-ChFdulEM.cjs';
|
|
3
3
|
import { SchemaDefinition, KoraError } from '@korajs/core';
|
|
4
4
|
import { AuthSyncBinding } from '@korajs/core/bindings';
|
|
5
5
|
export { AuthSyncBinding } from '@korajs/core/bindings';
|
|
6
|
-
import { A as AuthTokens } from './operation-encryptor-
|
|
7
|
-
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-
|
|
6
|
+
import { A as AuthTokens } from './operation-encryptor-DDdlb9bm.cjs';
|
|
7
|
+
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-DDdlb9bm.cjs';
|
|
8
8
|
|
|
9
9
|
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
10
10
|
/**
|
|
@@ -43,8 +43,19 @@ declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
|
43
43
|
*/
|
|
44
44
|
interface AuthSyncClient {
|
|
45
45
|
getAccessToken(): Promise<string | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Force a refresh even if the cached token looks valid locally. Called after
|
|
48
|
+
* the sync server ends a session with `AUTH_EXPIRED` / `AUTH_REVOKED`.
|
|
49
|
+
*/
|
|
50
|
+
refreshAccessToken?(): Promise<string | null>;
|
|
46
51
|
readonly state?: AuthState;
|
|
47
52
|
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
53
|
+
/** Stored session freshness (authenticated-offline support). */
|
|
54
|
+
readonly session?: AuthClientSession | null;
|
|
55
|
+
/** Unverified claims of the stored credentials, available offline. */
|
|
56
|
+
getStoredClaims?(): Promise<Record<string, unknown> | null>;
|
|
57
|
+
/** Notifies when session freshness changes (fresh, offline, locked). */
|
|
58
|
+
onSessionChange?(callback: (session: AuthClientSession | null) => void): () => void;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* Sync binding returned by {@link createKoraAuthSync}.
|
|
@@ -60,8 +71,9 @@ interface CreateKoraAuthSyncOptions {
|
|
|
60
71
|
/** Kora auth client from `createKoraAuth()`. */
|
|
61
72
|
authClient: AuthSyncClient;
|
|
62
73
|
/**
|
|
63
|
-
* Application schema. When provided, scope
|
|
64
|
-
*
|
|
74
|
+
* Application schema. When provided, a client-side scope hint is built from
|
|
75
|
+
* token claims and schema scope declarations. The server only uses it to
|
|
76
|
+
* NARROW its own grant; it never authorizes anything.
|
|
65
77
|
*/
|
|
66
78
|
schema?: SchemaDefinition;
|
|
67
79
|
/**
|
|
@@ -75,8 +87,14 @@ interface CreateKoraAuthSyncOptions {
|
|
|
75
87
|
/**
|
|
76
88
|
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
77
89
|
*
|
|
78
|
-
* Wires token refresh,
|
|
79
|
-
*
|
|
90
|
+
* Wires token refresh, a client-side scope hint, and device-bound sync node ids
|
|
91
|
+
* (`dev` claim) separate from the user id (`sub`).
|
|
92
|
+
*
|
|
93
|
+
* Offline-first: identity (user id, device id) comes from the stored session,
|
|
94
|
+
* not from token freshness. While the auth server is unreachable the binding
|
|
95
|
+
* keeps reporting the signed-in user (authenticated-offline, `token: null`), so
|
|
96
|
+
* the user's own local database opens and the app stays usable; only the sync
|
|
97
|
+
* transport waits for a fresh token.
|
|
80
98
|
*
|
|
81
99
|
* @example
|
|
82
100
|
* ```typescript
|
|
@@ -732,4 +750,4 @@ declare class AutoLockManager {
|
|
|
732
750
|
private _clearTimer;
|
|
733
751
|
}
|
|
734
752
|
|
|
735
|
-
export { AuthClient, AuthClientConfig, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|
|
753
|
+
export { AuthClient, AuthClientConfig, AuthClientSession, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState } from './create-org-session-
|
|
2
|
-
export {
|
|
1
|
+
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState, f as AuthClientSession } from './create-org-session-ChFdulEM.js';
|
|
2
|
+
export { g as AuthDeviceIdentity, h as AuthDeviceIdentityError, i as AuthError, j as AuthSession, k as AuthSessionSnapshot, l as AuthSessionStatus, m as AuthTokenStorageOptions, n as AuthUser, C as ClientInvitation, o as ClientMembership, p as ClientOrganization, q as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, r as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, M as MfaRequiredError, O as OAuthAuthorizationOptions, s as OAuthAuthorizationResult, t as OAuthCallbackParams, u as OrgClient, v as OrgClientConfig, w as OrgClientError, x as OrgSession, y as OrgSnapshot, P as PersistentDeviceIdentityOptions, z as checkOrgPermission, B as createAuthSession, E as createAuthTokenStorage, F as createDeviceKeyStore, G as createMemoryAuthTokenStorage, H as createOrgSession, J as createPersistentDeviceIdentity, K as createWebStorageAuthTokenStorage } from './create-org-session-ChFdulEM.js';
|
|
3
3
|
import { SchemaDefinition, KoraError } from '@korajs/core';
|
|
4
4
|
import { AuthSyncBinding } from '@korajs/core/bindings';
|
|
5
5
|
export { AuthSyncBinding } from '@korajs/core/bindings';
|
|
6
|
-
import { A as AuthTokens } from './operation-encryptor-
|
|
7
|
-
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-
|
|
6
|
+
import { A as AuthTokens } from './operation-encryptor-DDdlb9bm.js';
|
|
7
|
+
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-DDdlb9bm.js';
|
|
8
8
|
|
|
9
9
|
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
10
10
|
/**
|
|
@@ -43,8 +43,19 @@ declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
|
43
43
|
*/
|
|
44
44
|
interface AuthSyncClient {
|
|
45
45
|
getAccessToken(): Promise<string | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Force a refresh even if the cached token looks valid locally. Called after
|
|
48
|
+
* the sync server ends a session with `AUTH_EXPIRED` / `AUTH_REVOKED`.
|
|
49
|
+
*/
|
|
50
|
+
refreshAccessToken?(): Promise<string | null>;
|
|
46
51
|
readonly state?: AuthState;
|
|
47
52
|
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
53
|
+
/** Stored session freshness (authenticated-offline support). */
|
|
54
|
+
readonly session?: AuthClientSession | null;
|
|
55
|
+
/** Unverified claims of the stored credentials, available offline. */
|
|
56
|
+
getStoredClaims?(): Promise<Record<string, unknown> | null>;
|
|
57
|
+
/** Notifies when session freshness changes (fresh, offline, locked). */
|
|
58
|
+
onSessionChange?(callback: (session: AuthClientSession | null) => void): () => void;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* Sync binding returned by {@link createKoraAuthSync}.
|
|
@@ -60,8 +71,9 @@ interface CreateKoraAuthSyncOptions {
|
|
|
60
71
|
/** Kora auth client from `createKoraAuth()`. */
|
|
61
72
|
authClient: AuthSyncClient;
|
|
62
73
|
/**
|
|
63
|
-
* Application schema. When provided, scope
|
|
64
|
-
*
|
|
74
|
+
* Application schema. When provided, a client-side scope hint is built from
|
|
75
|
+
* token claims and schema scope declarations. The server only uses it to
|
|
76
|
+
* NARROW its own grant; it never authorizes anything.
|
|
65
77
|
*/
|
|
66
78
|
schema?: SchemaDefinition;
|
|
67
79
|
/**
|
|
@@ -75,8 +87,14 @@ interface CreateKoraAuthSyncOptions {
|
|
|
75
87
|
/**
|
|
76
88
|
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
77
89
|
*
|
|
78
|
-
* Wires token refresh,
|
|
79
|
-
*
|
|
90
|
+
* Wires token refresh, a client-side scope hint, and device-bound sync node ids
|
|
91
|
+
* (`dev` claim) separate from the user id (`sub`).
|
|
92
|
+
*
|
|
93
|
+
* Offline-first: identity (user id, device id) comes from the stored session,
|
|
94
|
+
* not from token freshness. While the auth server is unreachable the binding
|
|
95
|
+
* keeps reporting the signed-in user (authenticated-offline, `token: null`), so
|
|
96
|
+
* the user's own local database opens and the app stays usable; only the sync
|
|
97
|
+
* transport waits for a fresh token.
|
|
80
98
|
*
|
|
81
99
|
* @example
|
|
82
100
|
* ```typescript
|
|
@@ -732,4 +750,4 @@ declare class AutoLockManager {
|
|
|
732
750
|
private _clearTimer;
|
|
733
751
|
}
|
|
734
752
|
|
|
735
|
-
export { AuthClient, AuthClientConfig, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|
|
753
|
+
export { AuthClient, AuthClientConfig, AuthClientSession, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|