@korajs/auth 0.4.0 → 0.6.0
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 +81 -28
- package/dist/chunk-7OXBRSJL.js +203 -0
- package/dist/chunk-7OXBRSJL.js.map +1 -0
- package/dist/create-org-session-RsDj9cl4.d.cts +722 -0
- package/dist/create-org-session-RsDj9cl4.d.ts +722 -0
- package/dist/index.cjs +1146 -586
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -118
- package/dist/index.d.ts +67 -118
- package/dist/index.js +654 -258
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +297 -183
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +25 -209
- package/dist/react.d.ts +25 -209
- package/dist/react.js +134 -209
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +1611 -730
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +415 -224
- package/dist/server.d.ts +415 -224
- package/dist/server.js +1565 -704
- package/dist/server.js.map +1 -1
- package/dist/svelte.cjs +512 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +100 -0
- package/dist/svelte.d.ts +100 -0
- package/dist/svelte.js +278 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +565 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +136 -0
- package/dist/vue.d.ts +136 -0
- package/dist/vue.js +338 -0
- package/dist/vue.js.map +1 -0
- package/package.json +40 -6
- package/src/svelte/AuthProvider.svelte +37 -0
- package/src/svelte/OrgProvider.svelte +22 -0
- package/dist/org-client-BVTLKcIk.d.cts +0 -355
- package/dist/org-client-BVTLKcIk.d.ts +0 -355
package/dist/index.d.cts
CHANGED
|
@@ -1,148 +1,97 @@
|
|
|
1
|
-
|
|
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-RsDj9cl4.cjs';
|
|
2
|
+
export { f as AuthDeviceIdentity, g as AuthDeviceIdentityError, h as AuthError, i as AuthSession, j as AuthSessionSnapshot, k as AuthTokenStorageOptions, l as AuthUser, C as ClientInvitation, m as ClientMembership, n as ClientOrganization, o as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, p as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, O as OAuthAuthorizationOptions, q as OAuthAuthorizationResult, r as OAuthCallbackParams, s as OrgClient, t as OrgClientConfig, u as OrgClientError, v as OrgSession, w as OrgSnapshot, P as PersistentDeviceIdentityOptions, x as checkOrgPermission, y as createAuthSession, z as createAuthTokenStorage, B as createDeviceKeyStore, E as createMemoryAuthTokenStorage, F as createOrgSession, G as createPersistentDeviceIdentity, H as createWebStorageAuthTokenStorage } from './create-org-session-RsDj9cl4.cjs';
|
|
3
|
+
import { SchemaDefinition, KoraError } from '@korajs/core';
|
|
4
|
+
import { AuthSyncBinding } from '@korajs/core/bindings';
|
|
5
|
+
export { AuthSyncBinding } from '@korajs/core/bindings';
|
|
2
6
|
import { A as AuthTokens } from './operation-encryptor-DRmKNWpF.cjs';
|
|
3
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-DRmKNWpF.cjs';
|
|
4
|
-
import { KoraError } from '@korajs/core';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
* Thrown when a device key store operation fails.
|
|
8
|
-
* Provides context about the operation and the underlying cause.
|
|
9
|
-
*/
|
|
10
|
-
declare class DeviceKeyStoreError extends KoraError {
|
|
11
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Persistent storage interface for ECDSA P-256 device key pairs.
|
|
15
|
-
*
|
|
16
|
-
* Device key pairs are used for proof-of-possession authentication:
|
|
17
|
-
* the private key never leaves the device, and the public key is
|
|
18
|
-
* registered with the server. This store persists key pairs across
|
|
19
|
-
* page reloads and app restarts.
|
|
20
|
-
*
|
|
21
|
-
* In the browser, CryptoKey objects are structured-cloneable, so they
|
|
22
|
-
* can be stored directly in IndexedDB without serialization. In Node.js
|
|
23
|
-
* or test environments, an in-memory implementation is used instead.
|
|
24
|
-
*/
|
|
25
|
-
interface DeviceKeyStore {
|
|
9
|
+
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
26
10
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Overwrites any previously stored key pair for the same device ID.
|
|
30
|
-
*
|
|
31
|
-
* @param deviceId - The unique device identifier (typically a UUID v7)
|
|
32
|
-
* @param keyPair - The ECDSA P-256 CryptoKeyPair to store
|
|
33
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
11
|
+
* Complete token storage adapter. Use this for fully custom runtimes.
|
|
12
|
+
* If omitted, `credentialStore` is adapted automatically.
|
|
34
13
|
*/
|
|
35
|
-
|
|
14
|
+
storage?: AuthTokenStorage;
|
|
36
15
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param deviceId - The unique device identifier
|
|
40
|
-
* @returns The stored CryptoKeyPair, or null if no key pair exists for the device
|
|
41
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
16
|
+
* Runtime credential store used for tokens and stable device ID.
|
|
17
|
+
* Examples: Tauri secure storage, Expo SecureStore, iOS Keychain, Android Keystore.
|
|
42
18
|
*/
|
|
43
|
-
|
|
19
|
+
credentialStore?: AuthKeyValueStorage;
|
|
44
20
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* No-op if no key pair exists for the device ID.
|
|
48
|
-
*
|
|
49
|
-
* @param deviceId - The unique device identifier
|
|
50
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
21
|
+
* Explicit device identity provider. Set to `false` to disable automatic
|
|
22
|
+
* device binding during sign-up/sign-in.
|
|
51
23
|
*/
|
|
52
|
-
|
|
24
|
+
deviceIdentity?: AuthDeviceIdentityProvider | false;
|
|
53
25
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param deviceId - The unique device identifier
|
|
57
|
-
* @returns True if a key pair is stored for the device, false otherwise
|
|
58
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
26
|
+
* Device key store for runtimes without IndexedDB, such as React Native.
|
|
59
27
|
*/
|
|
60
|
-
|
|
28
|
+
deviceKeyStore?: DeviceKeyStore;
|
|
61
29
|
}
|
|
62
30
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* CryptoKey objects are structured-cloneable, so they can be stored
|
|
66
|
-
* directly in IndexedDB without needing to export/import them as JWK.
|
|
67
|
-
* This preserves the non-extractable flag on private keys, ensuring
|
|
68
|
-
* they cannot be read even from storage.
|
|
31
|
+
* Create a production-shaped Kora auth client with minimal setup.
|
|
69
32
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
33
|
+
* Defaults:
|
|
34
|
+
* - browser/Tauri WebView: localStorage for tokens, IndexedDB for device keys
|
|
35
|
+
* - desktop/mobile: pass `credentialStore` and optionally `deviceKeyStore`
|
|
36
|
+
* - automatic device identity is enabled when a persistent device ID store exists
|
|
37
|
+
*/
|
|
38
|
+
declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Minimal auth client surface required for sync integration.
|
|
42
|
+
* Matches {@link AuthClient} without importing implementation details.
|
|
43
|
+
*/
|
|
44
|
+
interface AuthSyncClient {
|
|
45
|
+
getAccessToken(): Promise<string | null>;
|
|
46
|
+
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sync binding returned by {@link createKoraAuthSync}.
|
|
50
|
+
* Passed to `createApp({ sync: { authClient } })` in korajs.
|
|
78
51
|
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
* @deprecated Use {@link AuthSyncBinding} from `@korajs/core/bindings` or `@korajs/auth`.
|
|
53
|
+
*/
|
|
54
|
+
type KoraAuthSyncBinding = AuthSyncBinding;
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for {@link createKoraAuthSync}.
|
|
82
57
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
interface CreateKoraAuthSyncOptions {
|
|
59
|
+
/** Kora auth client from `createKoraAuth()`. */
|
|
60
|
+
authClient: AuthSyncClient;
|
|
85
61
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
62
|
+
* Application schema. When provided, scope maps are built automatically
|
|
63
|
+
* from JWT claims and schema scope declarations.
|
|
64
|
+
*/
|
|
65
|
+
schema?: SchemaDefinition;
|
|
66
|
+
/**
|
|
67
|
+
* Custom claim → flat scope value mapping.
|
|
68
|
+
* Defaults to {@link extractScopeValuesFromClaims}.
|
|
91
69
|
*/
|
|
92
|
-
|
|
93
|
-
/** @inheritdoc */
|
|
94
|
-
saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
95
|
-
/** @inheritdoc */
|
|
96
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
97
|
-
/** @inheritdoc */
|
|
98
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
99
|
-
/** @inheritdoc */
|
|
100
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
70
|
+
scopeFromClaims?: (claims: Record<string, unknown>) => Record<string, unknown>;
|
|
101
71
|
}
|
|
102
72
|
/**
|
|
103
|
-
*
|
|
73
|
+
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
104
74
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* where IndexedDB is not available.
|
|
75
|
+
* Wires token refresh, automatic scope maps from JWT claims, and device-bound
|
|
76
|
+
* sync node ids (`dev` claim) separate from the user id (`sub`).
|
|
108
77
|
*
|
|
109
78
|
* @example
|
|
110
79
|
* ```typescript
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* await store.saveKeyPair('device-123', keyPair)
|
|
114
|
-
*
|
|
115
|
-
* const loaded = await store.loadKeyPair('device-123')
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare class InMemoryDeviceKeyStore implements DeviceKeyStore {
|
|
119
|
-
private readonly store;
|
|
120
|
-
/** @inheritdoc */
|
|
121
|
-
saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
122
|
-
/** @inheritdoc */
|
|
123
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
124
|
-
/** @inheritdoc */
|
|
125
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
126
|
-
/** @inheritdoc */
|
|
127
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Creates a DeviceKeyStore appropriate for the current environment.
|
|
131
|
-
*
|
|
132
|
-
* In browsers where IndexedDB is available, returns an {@link IndexedDBDeviceKeyStore}
|
|
133
|
-
* that persists CryptoKeyPair objects as structured clones. In Node.js, SSR,
|
|
134
|
-
* or environments without IndexedDB, returns an {@link InMemoryDeviceKeyStore}.
|
|
80
|
+
* import { createKoraAuth, createKoraAuthSync } from '@korajs/auth'
|
|
81
|
+
* import { createApp } from 'korajs'
|
|
135
82
|
*
|
|
136
|
-
*
|
|
83
|
+
* const authClient = createKoraAuth({ serverUrl: 'https://api.example.com' })
|
|
137
84
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
85
|
+
* const app = createApp({
|
|
86
|
+
* schema,
|
|
87
|
+
* sync: {
|
|
88
|
+
* url: 'wss://api.example.com/kora-sync',
|
|
89
|
+
* authClient: createKoraAuthSync({ authClient, schema }),
|
|
90
|
+
* },
|
|
91
|
+
* })
|
|
143
92
|
* ```
|
|
144
93
|
*/
|
|
145
|
-
declare function
|
|
94
|
+
declare function createKoraAuthSync(options: CreateKoraAuthSyncOptions): AuthSyncBinding;
|
|
146
95
|
|
|
147
96
|
/**
|
|
148
97
|
* Client-side token storage for Kora auth tokens.
|
|
@@ -780,4 +729,4 @@ declare class AutoLockManager {
|
|
|
780
729
|
private _clearTimer;
|
|
781
730
|
}
|
|
782
731
|
|
|
783
|
-
export { AuthTokens, type AutoLockConfig, AutoLockManager, type
|
|
732
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,148 +1,97 @@
|
|
|
1
|
-
|
|
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-RsDj9cl4.js';
|
|
2
|
+
export { f as AuthDeviceIdentity, g as AuthDeviceIdentityError, h as AuthError, i as AuthSession, j as AuthSessionSnapshot, k as AuthTokenStorageOptions, l as AuthUser, C as ClientInvitation, m as ClientMembership, n as ClientOrganization, o as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, p as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, O as OAuthAuthorizationOptions, q as OAuthAuthorizationResult, r as OAuthCallbackParams, s as OrgClient, t as OrgClientConfig, u as OrgClientError, v as OrgSession, w as OrgSnapshot, P as PersistentDeviceIdentityOptions, x as checkOrgPermission, y as createAuthSession, z as createAuthTokenStorage, B as createDeviceKeyStore, E as createMemoryAuthTokenStorage, F as createOrgSession, G as createPersistentDeviceIdentity, H as createWebStorageAuthTokenStorage } from './create-org-session-RsDj9cl4.js';
|
|
3
|
+
import { SchemaDefinition, KoraError } from '@korajs/core';
|
|
4
|
+
import { AuthSyncBinding } from '@korajs/core/bindings';
|
|
5
|
+
export { AuthSyncBinding } from '@korajs/core/bindings';
|
|
2
6
|
import { A as AuthTokens } from './operation-encryptor-DRmKNWpF.js';
|
|
3
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-DRmKNWpF.js';
|
|
4
|
-
import { KoraError } from '@korajs/core';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
* Thrown when a device key store operation fails.
|
|
8
|
-
* Provides context about the operation and the underlying cause.
|
|
9
|
-
*/
|
|
10
|
-
declare class DeviceKeyStoreError extends KoraError {
|
|
11
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Persistent storage interface for ECDSA P-256 device key pairs.
|
|
15
|
-
*
|
|
16
|
-
* Device key pairs are used for proof-of-possession authentication:
|
|
17
|
-
* the private key never leaves the device, and the public key is
|
|
18
|
-
* registered with the server. This store persists key pairs across
|
|
19
|
-
* page reloads and app restarts.
|
|
20
|
-
*
|
|
21
|
-
* In the browser, CryptoKey objects are structured-cloneable, so they
|
|
22
|
-
* can be stored directly in IndexedDB without serialization. In Node.js
|
|
23
|
-
* or test environments, an in-memory implementation is used instead.
|
|
24
|
-
*/
|
|
25
|
-
interface DeviceKeyStore {
|
|
9
|
+
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
26
10
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Overwrites any previously stored key pair for the same device ID.
|
|
30
|
-
*
|
|
31
|
-
* @param deviceId - The unique device identifier (typically a UUID v7)
|
|
32
|
-
* @param keyPair - The ECDSA P-256 CryptoKeyPair to store
|
|
33
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
11
|
+
* Complete token storage adapter. Use this for fully custom runtimes.
|
|
12
|
+
* If omitted, `credentialStore` is adapted automatically.
|
|
34
13
|
*/
|
|
35
|
-
|
|
14
|
+
storage?: AuthTokenStorage;
|
|
36
15
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param deviceId - The unique device identifier
|
|
40
|
-
* @returns The stored CryptoKeyPair, or null if no key pair exists for the device
|
|
41
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
16
|
+
* Runtime credential store used for tokens and stable device ID.
|
|
17
|
+
* Examples: Tauri secure storage, Expo SecureStore, iOS Keychain, Android Keystore.
|
|
42
18
|
*/
|
|
43
|
-
|
|
19
|
+
credentialStore?: AuthKeyValueStorage;
|
|
44
20
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* No-op if no key pair exists for the device ID.
|
|
48
|
-
*
|
|
49
|
-
* @param deviceId - The unique device identifier
|
|
50
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
21
|
+
* Explicit device identity provider. Set to `false` to disable automatic
|
|
22
|
+
* device binding during sign-up/sign-in.
|
|
51
23
|
*/
|
|
52
|
-
|
|
24
|
+
deviceIdentity?: AuthDeviceIdentityProvider | false;
|
|
53
25
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param deviceId - The unique device identifier
|
|
57
|
-
* @returns True if a key pair is stored for the device, false otherwise
|
|
58
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
26
|
+
* Device key store for runtimes without IndexedDB, such as React Native.
|
|
59
27
|
*/
|
|
60
|
-
|
|
28
|
+
deviceKeyStore?: DeviceKeyStore;
|
|
61
29
|
}
|
|
62
30
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* CryptoKey objects are structured-cloneable, so they can be stored
|
|
66
|
-
* directly in IndexedDB without needing to export/import them as JWK.
|
|
67
|
-
* This preserves the non-extractable flag on private keys, ensuring
|
|
68
|
-
* they cannot be read even from storage.
|
|
31
|
+
* Create a production-shaped Kora auth client with minimal setup.
|
|
69
32
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
33
|
+
* Defaults:
|
|
34
|
+
* - browser/Tauri WebView: localStorage for tokens, IndexedDB for device keys
|
|
35
|
+
* - desktop/mobile: pass `credentialStore` and optionally `deviceKeyStore`
|
|
36
|
+
* - automatic device identity is enabled when a persistent device ID store exists
|
|
37
|
+
*/
|
|
38
|
+
declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Minimal auth client surface required for sync integration.
|
|
42
|
+
* Matches {@link AuthClient} without importing implementation details.
|
|
43
|
+
*/
|
|
44
|
+
interface AuthSyncClient {
|
|
45
|
+
getAccessToken(): Promise<string | null>;
|
|
46
|
+
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sync binding returned by {@link createKoraAuthSync}.
|
|
50
|
+
* Passed to `createApp({ sync: { authClient } })` in korajs.
|
|
78
51
|
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
* @deprecated Use {@link AuthSyncBinding} from `@korajs/core/bindings` or `@korajs/auth`.
|
|
53
|
+
*/
|
|
54
|
+
type KoraAuthSyncBinding = AuthSyncBinding;
|
|
55
|
+
/**
|
|
56
|
+
* Configuration for {@link createKoraAuthSync}.
|
|
82
57
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
interface CreateKoraAuthSyncOptions {
|
|
59
|
+
/** Kora auth client from `createKoraAuth()`. */
|
|
60
|
+
authClient: AuthSyncClient;
|
|
85
61
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
62
|
+
* Application schema. When provided, scope maps are built automatically
|
|
63
|
+
* from JWT claims and schema scope declarations.
|
|
64
|
+
*/
|
|
65
|
+
schema?: SchemaDefinition;
|
|
66
|
+
/**
|
|
67
|
+
* Custom claim → flat scope value mapping.
|
|
68
|
+
* Defaults to {@link extractScopeValuesFromClaims}.
|
|
91
69
|
*/
|
|
92
|
-
|
|
93
|
-
/** @inheritdoc */
|
|
94
|
-
saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
95
|
-
/** @inheritdoc */
|
|
96
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
97
|
-
/** @inheritdoc */
|
|
98
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
99
|
-
/** @inheritdoc */
|
|
100
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
70
|
+
scopeFromClaims?: (claims: Record<string, unknown>) => Record<string, unknown>;
|
|
101
71
|
}
|
|
102
72
|
/**
|
|
103
|
-
*
|
|
73
|
+
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
104
74
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* where IndexedDB is not available.
|
|
75
|
+
* Wires token refresh, automatic scope maps from JWT claims, and device-bound
|
|
76
|
+
* sync node ids (`dev` claim) separate from the user id (`sub`).
|
|
108
77
|
*
|
|
109
78
|
* @example
|
|
110
79
|
* ```typescript
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* await store.saveKeyPair('device-123', keyPair)
|
|
114
|
-
*
|
|
115
|
-
* const loaded = await store.loadKeyPair('device-123')
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare class InMemoryDeviceKeyStore implements DeviceKeyStore {
|
|
119
|
-
private readonly store;
|
|
120
|
-
/** @inheritdoc */
|
|
121
|
-
saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
122
|
-
/** @inheritdoc */
|
|
123
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
124
|
-
/** @inheritdoc */
|
|
125
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
126
|
-
/** @inheritdoc */
|
|
127
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Creates a DeviceKeyStore appropriate for the current environment.
|
|
131
|
-
*
|
|
132
|
-
* In browsers where IndexedDB is available, returns an {@link IndexedDBDeviceKeyStore}
|
|
133
|
-
* that persists CryptoKeyPair objects as structured clones. In Node.js, SSR,
|
|
134
|
-
* or environments without IndexedDB, returns an {@link InMemoryDeviceKeyStore}.
|
|
80
|
+
* import { createKoraAuth, createKoraAuthSync } from '@korajs/auth'
|
|
81
|
+
* import { createApp } from 'korajs'
|
|
135
82
|
*
|
|
136
|
-
*
|
|
83
|
+
* const authClient = createKoraAuth({ serverUrl: 'https://api.example.com' })
|
|
137
84
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
85
|
+
* const app = createApp({
|
|
86
|
+
* schema,
|
|
87
|
+
* sync: {
|
|
88
|
+
* url: 'wss://api.example.com/kora-sync',
|
|
89
|
+
* authClient: createKoraAuthSync({ authClient, schema }),
|
|
90
|
+
* },
|
|
91
|
+
* })
|
|
143
92
|
* ```
|
|
144
93
|
*/
|
|
145
|
-
declare function
|
|
94
|
+
declare function createKoraAuthSync(options: CreateKoraAuthSyncOptions): AuthSyncBinding;
|
|
146
95
|
|
|
147
96
|
/**
|
|
148
97
|
* Client-side token storage for Kora auth tokens.
|
|
@@ -780,4 +729,4 @@ declare class AutoLockManager {
|
|
|
780
729
|
private _clearTimer;
|
|
781
730
|
}
|
|
782
731
|
|
|
783
|
-
export { AuthTokens, type AutoLockConfig, AutoLockManager, type
|
|
732
|
+
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 };
|