@icp-sdk/auth 6.0.0 → 6.2.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 +85 -13
- package/dist/esm/client/auth-client.d.ts +57 -31
- package/dist/esm/client/auth-client.js +120 -54
- package/dist/esm/client/auth-client.js.map +1 -1
- package/dist/esm/client/idle-manager.d.ts +1 -1
- package/dist/esm/client/idle-manager.js +1 -1
- package/package.json +2 -2
- package/src/client/auth-client.ts +150 -73
- package/src/client/idle-manager.ts +1 -1
package/README.md
CHANGED
|
@@ -42,22 +42,20 @@ import { AuthClient } from '@icp-sdk/auth/client';
|
|
|
42
42
|
|
|
43
43
|
const authClient = new AuthClient();
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
const identity = await authClient.getIdentity();
|
|
48
|
-
console.log('Restored session:', identity.getPrincipal().toString());
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Log in
|
|
45
|
+
// restore an existing session if there is one, otherwise sign in
|
|
46
|
+
let identity;
|
|
52
47
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
identity = authClient.isAuthenticated()
|
|
49
|
+
? await authClient.getIdentity()
|
|
50
|
+
: await authClient.signIn();
|
|
56
51
|
} catch (error) {
|
|
57
|
-
console.error('
|
|
52
|
+
console.error('Sign-in failed:', error);
|
|
53
|
+
throw error;
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
console.log('Identity:', identity.getPrincipal().toString());
|
|
57
|
+
|
|
58
|
+
// later, to end the session
|
|
61
59
|
await authClient.logout();
|
|
62
60
|
```
|
|
63
61
|
|
|
@@ -69,8 +67,82 @@ Skip the Internet Identity authentication method screen and offer sign-in option
|
|
|
69
67
|
const authClient = new AuthClient({
|
|
70
68
|
openIdProvider: 'google', // or 'apple' or 'microsoft'
|
|
71
69
|
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Requesting Identity Attributes
|
|
73
|
+
|
|
74
|
+
Internet Identity can provide signed identity attributes (e.g., email) alongside authentication. Your backend canister initiates the flow by issuing a nonce tied to the action — this way, even if an attribute bundle is intercepted, it can't be replayed or used for a different action.
|
|
75
|
+
|
|
76
|
+
Here's a registration flow where the backend needs the user's email:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { AuthClient } from '@icp-sdk/auth/client';
|
|
80
|
+
import { AttributesIdentity } from '@icp-sdk/core/identity';
|
|
81
|
+
import { HttpAgent, Actor } from '@icp-sdk/core/agent';
|
|
82
|
+
|
|
83
|
+
const authClient = new AuthClient();
|
|
84
|
+
|
|
85
|
+
// the backend issues a nonce scoped to registration —
|
|
86
|
+
// this starts the action and binds the upcoming attributes to it
|
|
87
|
+
const anonymousAgent = await HttpAgent.create();
|
|
88
|
+
const backend = Actor.createActor(backendIdl, { agent: anonymousAgent, canisterId });
|
|
89
|
+
const nonce: Uint8Array = await backend.registerBegin();
|
|
90
|
+
|
|
91
|
+
// sign-in and attribute request happen in parallel — the user sees a single II interaction
|
|
92
|
+
try {
|
|
93
|
+
const signInPromise = authClient.signIn();
|
|
94
|
+
const attributesPromise = authClient.requestAttributes({ keys: ['email'], nonce });
|
|
95
|
+
|
|
96
|
+
await signInPromise;
|
|
97
|
+
const { data, signature } = await attributesPromise;
|
|
98
|
+
|
|
99
|
+
// wrap the identity so the signed attributes are included in the canister call
|
|
100
|
+
const identityWithAttributes = new AttributesIdentity({
|
|
101
|
+
inner: await authClient.getIdentity(),
|
|
102
|
+
attributes: { data, signature },
|
|
103
|
+
signer: { canisterId: Principal.fromText('rdmx6-jaaaa-aaaaa-aaadq-cai') }, // Internet Identity canister ID
|
|
104
|
+
});
|
|
105
|
+
const agent = await HttpAgent.create({ identity: identityWithAttributes });
|
|
106
|
+
const app = Actor.createActor(appIdl, { agent, canisterId });
|
|
107
|
+
|
|
108
|
+
// the backend verifies the nonce, origin, and timestamp, then extracts the email
|
|
109
|
+
await app.registerFinish();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Registration failed:', error);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The signed attribute bundle includes implicit fields that your backend canister should verify:
|
|
116
|
+
|
|
117
|
+
- **`implicit:nonce`** — ties the attributes to a specific canister-initiated action, preventing replay and cross-action reuse. Must originate from the backend, not the frontend.
|
|
118
|
+
- **`implicit:origin`** — the requesting origin, verified by the canister to prevent a malicious dapp from forwarding attribute bundles to your backend.
|
|
119
|
+
- **`implicit:issued_at_timestamp_ns`** — issuance timestamp, allowing the canister to reject stale attributes even if the nonce hasn't expired yet.
|
|
120
|
+
|
|
121
|
+
> Attributes can also be requested after sign-in — for example, when a user later triggers an action like linking an email. The flow is the same: the backend issues a nonce for that action, the frontend calls `requestAttributes`, and the backend verifies the result.
|
|
122
|
+
|
|
123
|
+
#### OpenID-Scoped Attributes
|
|
124
|
+
|
|
125
|
+
When using one-click sign-in, attributes can be scoped to the OpenID provider. Scoped attributes have implicit consent — the user authenticates and shares attributes in a single step without an additional prompt:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { AuthClient, scopedKeys } from '@icp-sdk/auth/client';
|
|
129
|
+
|
|
130
|
+
const authClient = new AuthClient({
|
|
131
|
+
openIdProvider: 'google',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const nonce: Uint8Array = await backend.registerBegin();
|
|
135
|
+
const signInPromise = authClient.signIn();
|
|
136
|
+
// requests name, email, and verified_email from the
|
|
137
|
+
// Google account linked to the user's Internet Identity
|
|
138
|
+
const attributesPromise = authClient.requestAttributes({
|
|
139
|
+
keys: scopedKeys({ openIdProvider: 'google' }),
|
|
140
|
+
nonce,
|
|
141
|
+
});
|
|
72
142
|
|
|
73
|
-
await
|
|
143
|
+
await signInPromise;
|
|
144
|
+
const { data, signature } = await attributesPromise;
|
|
145
|
+
// ... wrap with AttributesIdentity and complete the action as above
|
|
74
146
|
```
|
|
75
147
|
|
|
76
148
|
Additional documentation can be found [here](https://js.icp.build/auth/latest/).
|
|
@@ -7,6 +7,12 @@ declare const ECDSA_KEY_LABEL = "ECDSA";
|
|
|
7
7
|
declare const ED25519_KEY_LABEL = "Ed25519";
|
|
8
8
|
type BaseKeyType = typeof ECDSA_KEY_LABEL | typeof ED25519_KEY_LABEL;
|
|
9
9
|
export type OpenIdProvider = 'google' | 'apple' | 'microsoft';
|
|
10
|
+
export declare const OPENID_PROVIDER_URLS: {
|
|
11
|
+
readonly google: "https://accounts.google.com";
|
|
12
|
+
readonly apple: "https://appleid.apple.com";
|
|
13
|
+
readonly microsoft: "https://login.microsoftonline.com/{tid}/v2.0";
|
|
14
|
+
};
|
|
15
|
+
declare const DEFAULT_OPENID_SCOPE_KEYS: readonly ["name", "email", "verified_email"];
|
|
10
16
|
/**
|
|
11
17
|
* Options for creating an {@link AuthClient}.
|
|
12
18
|
*/
|
|
@@ -21,7 +27,7 @@ export interface AuthClientCreateOptions {
|
|
|
21
27
|
*/
|
|
22
28
|
storage?: AuthClientStorage;
|
|
23
29
|
/**
|
|
24
|
-
* Type of session key to generate on each
|
|
30
|
+
* Type of session key to generate on each sign-in.
|
|
25
31
|
*
|
|
26
32
|
* Use `'Ed25519'` when your storage provider does not support `CryptoKey`.
|
|
27
33
|
* @default 'ECDSA'
|
|
@@ -66,12 +72,10 @@ export interface IdleOptions extends IdleManagerOptions {
|
|
|
66
72
|
*/
|
|
67
73
|
disableDefaultIdleCallback?: boolean;
|
|
68
74
|
}
|
|
69
|
-
export type OnSuccessFunc = () => void | Promise<void>;
|
|
70
|
-
export type OnErrorFunc = (error?: string) => void | Promise<void>;
|
|
71
75
|
/**
|
|
72
|
-
* Options for {@link AuthClient.
|
|
76
|
+
* Options for {@link AuthClient.signIn}.
|
|
73
77
|
*/
|
|
74
|
-
export interface
|
|
78
|
+
export interface AuthClientSignInOptions {
|
|
75
79
|
/**
|
|
76
80
|
* Maximum lifetime of the delegation in nanoseconds.
|
|
77
81
|
* @default 8 hours
|
|
@@ -81,15 +85,10 @@ export interface AuthClientLoginOptions {
|
|
|
81
85
|
* Restrict the delegation to specific canisters.
|
|
82
86
|
*/
|
|
83
87
|
targets?: Principal[];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Called when login fails. When provided the error is **not** re-thrown,
|
|
90
|
-
* allowing the caller to handle it via this callback instead.
|
|
91
|
-
*/
|
|
92
|
-
onError?: OnErrorFunc;
|
|
88
|
+
}
|
|
89
|
+
export interface SignedAttributes {
|
|
90
|
+
data: Uint8Array;
|
|
91
|
+
signature: Uint8Array;
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* Manages authentication and identity for Internet Computer web apps.
|
|
@@ -97,13 +96,9 @@ export interface AuthClientLoginOptions {
|
|
|
97
96
|
* @example
|
|
98
97
|
* const authClient = new AuthClient();
|
|
99
98
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* await authClient.login({
|
|
105
|
-
* onSuccess: () => console.log('Logged in!'),
|
|
106
|
-
* });
|
|
99
|
+
* const identity = authClient.isAuthenticated()
|
|
100
|
+
* ? await authClient.getIdentity()
|
|
101
|
+
* : await authClient.signIn();
|
|
107
102
|
*/
|
|
108
103
|
export declare class AuthClient {
|
|
109
104
|
#private;
|
|
@@ -118,22 +113,35 @@ export declare class AuthClient {
|
|
|
118
113
|
*/
|
|
119
114
|
isAuthenticated(): boolean;
|
|
120
115
|
/**
|
|
121
|
-
* Opens the identity provider
|
|
116
|
+
* Opens the identity provider, requests a delegation, and returns the authenticated identity.
|
|
122
117
|
*
|
|
123
|
-
* @param options -
|
|
118
|
+
* @param options - Sign-in options.
|
|
124
119
|
* @param options.maxTimeToLive - Maximum lifetime of the delegation in nanoseconds.
|
|
125
120
|
* @param options.targets - Restrict the delegation to specific canisters.
|
|
126
|
-
* @
|
|
127
|
-
* @
|
|
128
|
-
* @throws When authentication fails and no `onError` callback is provided.
|
|
121
|
+
* @returns The authenticated identity.
|
|
122
|
+
* @throws When authentication fails.
|
|
129
123
|
*
|
|
130
124
|
* @example
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
125
|
+
* try {
|
|
126
|
+
* const identity = await authClient.signIn();
|
|
127
|
+
* } catch (error) {
|
|
128
|
+
* console.error('Sign-in failed:', error);
|
|
129
|
+
* }
|
|
135
130
|
*/
|
|
136
|
-
|
|
131
|
+
signIn(options?: AuthClientSignInOptions): Promise<Identity>;
|
|
132
|
+
/**
|
|
133
|
+
* Requests signed identity attributes from the identity provider.
|
|
134
|
+
*
|
|
135
|
+
* @param params - Request parameters.
|
|
136
|
+
* @param params.keys - Attribute keys to request (e.g. `['email', 'name']`).
|
|
137
|
+
* @param params.nonce - 32-byte nonce issued by the RP canister.
|
|
138
|
+
* @returns Signed attribute data and signature.
|
|
139
|
+
* @throws When the identity provider returns an error or an invalid response.
|
|
140
|
+
*/
|
|
141
|
+
requestAttributes(params: {
|
|
142
|
+
keys: string[];
|
|
143
|
+
nonce: Uint8Array;
|
|
144
|
+
}): Promise<SignedAttributes>;
|
|
137
145
|
/**
|
|
138
146
|
* Clears the stored session and resets the client to an anonymous state.
|
|
139
147
|
*
|
|
@@ -144,4 +152,22 @@ export declare class AuthClient {
|
|
|
144
152
|
returnTo?: string;
|
|
145
153
|
}): Promise<void>;
|
|
146
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Scopes attribute keys to an OpenID provider.
|
|
157
|
+
*
|
|
158
|
+
* When using one-click sign-in, attributes can be scoped to the same provider
|
|
159
|
+
* so the user grants access in a single step without an additional prompt.
|
|
160
|
+
*
|
|
161
|
+
* @param params.openIdProvider - The OpenID provider the keys should be scoped to.
|
|
162
|
+
* @param params.keys - The attribute keys to scope. Defaults to `['name', 'email', 'verified_email']`.
|
|
163
|
+
* @returns The scoped attribute keys as `openid:<provider-url>:<key>`.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* scopedKeys({ openIdProvider: 'google', keys: ['email'] });
|
|
167
|
+
* // ['openid:https://accounts.google.com:email']
|
|
168
|
+
*/
|
|
169
|
+
export declare function scopedKeys<P extends keyof typeof OPENID_PROVIDER_URLS, K extends string = (typeof DEFAULT_OPENID_SCOPE_KEYS)[number]>(params: {
|
|
170
|
+
openIdProvider: P;
|
|
171
|
+
keys?: readonly K[];
|
|
172
|
+
}): `openid:${(typeof OPENID_PROVIDER_URLS)[P]}:${K}`[];
|
|
147
173
|
export {};
|
|
@@ -14,24 +14,21 @@ const ED25519_KEY_LABEL = 'Ed25519';
|
|
|
14
14
|
// localStorage key used to cache the delegation expiration so that
|
|
15
15
|
// isAuthenticated() can answer synchronously without hitting IndexedDB.
|
|
16
16
|
const KEY_STORAGE_EXPIRATION = 'ic-delegation_expiration';
|
|
17
|
-
const OPENID_PROVIDER_URLS = {
|
|
17
|
+
export const OPENID_PROVIDER_URLS = {
|
|
18
18
|
google: 'https://accounts.google.com',
|
|
19
19
|
apple: 'https://appleid.apple.com',
|
|
20
20
|
microsoft: 'https://login.microsoftonline.com/{tid}/v2.0',
|
|
21
21
|
};
|
|
22
|
+
const DEFAULT_OPENID_SCOPE_KEYS = ['name', 'email', 'verified_email'];
|
|
22
23
|
/**
|
|
23
24
|
* Manages authentication and identity for Internet Computer web apps.
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* const authClient = new AuthClient();
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* await authClient.login({
|
|
33
|
-
* onSuccess: () => console.log('Logged in!'),
|
|
34
|
-
* });
|
|
29
|
+
* const identity = authClient.isAuthenticated()
|
|
30
|
+
* ? await authClient.getIdentity()
|
|
31
|
+
* : await authClient.signIn();
|
|
35
32
|
*/
|
|
36
33
|
export class AuthClient {
|
|
37
34
|
#identity = new AnonymousIdentity();
|
|
@@ -80,59 +77,80 @@ export class AuthClient {
|
|
|
80
77
|
return nowNs < expiration;
|
|
81
78
|
}
|
|
82
79
|
/**
|
|
83
|
-
* Opens the identity provider
|
|
80
|
+
* Opens the identity provider, requests a delegation, and returns the authenticated identity.
|
|
84
81
|
*
|
|
85
|
-
* @param options -
|
|
82
|
+
* @param options - Sign-in options.
|
|
86
83
|
* @param options.maxTimeToLive - Maximum lifetime of the delegation in nanoseconds.
|
|
87
84
|
* @param options.targets - Restrict the delegation to specific canisters.
|
|
88
|
-
* @
|
|
89
|
-
* @
|
|
90
|
-
* @throws When authentication fails and no `onError` callback is provided.
|
|
85
|
+
* @returns The authenticated identity.
|
|
86
|
+
* @throws When authentication fails.
|
|
91
87
|
*
|
|
92
88
|
* @example
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
89
|
+
* try {
|
|
90
|
+
* const identity = await authClient.signIn();
|
|
91
|
+
* } catch (error) {
|
|
92
|
+
* console.error('Sign-in failed:', error);
|
|
93
|
+
* }
|
|
94
|
+
*/
|
|
95
|
+
async signIn(options) {
|
|
96
|
+
await this.#signer.openChannel();
|
|
97
|
+
const maxTimeToLive = options?.maxTimeToLive ?? DEFAULT_MAX_TIME_TO_LIVE;
|
|
98
|
+
// Fresh key per sign-in so each session has its own cryptographic identity.
|
|
99
|
+
const key = this.#options.identity ?? (await generateKey(this.#options.keyType ?? ECDSA_KEY_LABEL));
|
|
100
|
+
const delegationChain = await this.#signer.requestDelegation({
|
|
101
|
+
publicKey: key.getPublicKey(),
|
|
102
|
+
targets: options?.targets,
|
|
103
|
+
maxTimeToLive,
|
|
104
|
+
});
|
|
105
|
+
this.#chain = delegationChain;
|
|
106
|
+
// PartialIdentity only has the public key — no signing capability.
|
|
107
|
+
if ('toDer' in key) {
|
|
108
|
+
this.#identity = PartialDelegationIdentity.fromDelegation(key, this.#chain);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.#identity = DelegationIdentity.fromDelegation(key, this.#chain);
|
|
112
|
+
}
|
|
113
|
+
const idleOptions = this.#options?.idleOptions;
|
|
114
|
+
if (!this.idleManager && !idleOptions?.disableIdle) {
|
|
115
|
+
this.idleManager = IdleManager.create(idleOptions);
|
|
116
|
+
this.#registerDefaultIdleCallback();
|
|
117
|
+
}
|
|
118
|
+
// Persist so the session survives page reloads.
|
|
119
|
+
await persistChain(this.#storage, this.#chain);
|
|
120
|
+
await persistKey(this.#storage, key);
|
|
121
|
+
return this.#identity;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Requests signed identity attributes from the identity provider.
|
|
125
|
+
*
|
|
126
|
+
* @param params - Request parameters.
|
|
127
|
+
* @param params.keys - Attribute keys to request (e.g. `['email', 'name']`).
|
|
128
|
+
* @param params.nonce - 32-byte nonce issued by the RP canister.
|
|
129
|
+
* @returns Signed attribute data and signature.
|
|
130
|
+
* @throws When the identity provider returns an error or an invalid response.
|
|
97
131
|
*/
|
|
98
|
-
async
|
|
132
|
+
async requestAttributes(params) {
|
|
133
|
+
const nonceBytes = params.nonce;
|
|
134
|
+
const response = await this.#signer.sendRequest({
|
|
135
|
+
jsonrpc: '2.0',
|
|
136
|
+
method: 'ii-icrc3-attributes',
|
|
137
|
+
params: { keys: params.keys, nonce: toBase64(nonceBytes) },
|
|
138
|
+
});
|
|
139
|
+
if ('error' in response) {
|
|
140
|
+
throw new Error(response.error.message);
|
|
141
|
+
}
|
|
142
|
+
const result = response.result;
|
|
143
|
+
if (typeof result?.data !== 'string' || typeof result?.signature !== 'string') {
|
|
144
|
+
throw new Error('Invalid response: missing data or signature');
|
|
145
|
+
}
|
|
99
146
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const delegationChain = await this.#signer.requestDelegation({
|
|
105
|
-
publicKey: key.getPublicKey(),
|
|
106
|
-
targets: options?.targets,
|
|
107
|
-
maxTimeToLive,
|
|
108
|
-
});
|
|
109
|
-
this.#chain = delegationChain;
|
|
110
|
-
// PartialIdentity only has the public key — no signing capability.
|
|
111
|
-
if ('toDer' in key) {
|
|
112
|
-
this.#identity = PartialDelegationIdentity.fromDelegation(key, this.#chain);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.#identity = DelegationIdentity.fromDelegation(key, this.#chain);
|
|
116
|
-
}
|
|
117
|
-
const idleOptions = this.#options?.idleOptions;
|
|
118
|
-
if (!this.idleManager && !idleOptions?.disableIdle) {
|
|
119
|
-
this.idleManager = IdleManager.create(idleOptions);
|
|
120
|
-
this.#registerDefaultIdleCallback();
|
|
121
|
-
}
|
|
122
|
-
// Persist so the session survives page reloads.
|
|
123
|
-
await persistChain(this.#storage, this.#chain);
|
|
124
|
-
await persistKey(this.#storage, key);
|
|
125
|
-
await options?.onSuccess?.();
|
|
147
|
+
return {
|
|
148
|
+
data: fromBase64(result.data),
|
|
149
|
+
signature: fromBase64(result.signature),
|
|
150
|
+
};
|
|
126
151
|
}
|
|
127
|
-
catch (
|
|
128
|
-
|
|
129
|
-
// Otherwise, re-throw so the error can be caught with try/catch or .catch().
|
|
130
|
-
if (options?.onError) {
|
|
131
|
-
await options.onError(error instanceof Error ? error.message : String(error));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
152
|
+
catch (cause) {
|
|
153
|
+
throw new Error('Invalid response: data or signature is not valid base64', { cause });
|
|
136
154
|
}
|
|
137
155
|
}
|
|
138
156
|
/**
|
|
@@ -163,7 +181,7 @@ export class AuthClient {
|
|
|
163
181
|
}
|
|
164
182
|
// Attempts to restore a previous session (key + delegation chain) from
|
|
165
183
|
// storage. If found and still valid, sets #identity and #chain so the
|
|
166
|
-
// client is ready to use without a new
|
|
184
|
+
// client is ready to use without a new signIn().
|
|
167
185
|
async #hydrate() {
|
|
168
186
|
const key = this.#options.identity ??
|
|
169
187
|
(await restoreKey(this.#storage, this.#options.keyType ?? ECDSA_KEY_LABEL));
|
|
@@ -194,6 +212,35 @@ export class AuthClient {
|
|
|
194
212
|
}
|
|
195
213
|
}
|
|
196
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Encodes a Uint8Array to a base64 string.
|
|
217
|
+
* @param bytes - The bytes to encode.
|
|
218
|
+
*/
|
|
219
|
+
function toBase64(bytes) {
|
|
220
|
+
if ('toBase64' in bytes && typeof bytes.toBase64 === 'function') {
|
|
221
|
+
return bytes.toBase64();
|
|
222
|
+
}
|
|
223
|
+
let binary = '';
|
|
224
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
225
|
+
binary += String.fromCharCode(bytes[i]);
|
|
226
|
+
}
|
|
227
|
+
return globalThis.btoa(binary);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Decodes a base64 string to a Uint8Array.
|
|
231
|
+
* @param str - The base64-encoded string.
|
|
232
|
+
*/
|
|
233
|
+
function fromBase64(str) {
|
|
234
|
+
if ('fromBase64' in Uint8Array && typeof Uint8Array.fromBase64 === 'function') {
|
|
235
|
+
return Uint8Array.fromBase64(str);
|
|
236
|
+
}
|
|
237
|
+
const binary = globalThis.atob(str);
|
|
238
|
+
const bytes = new Uint8Array(binary.length);
|
|
239
|
+
for (let i = 0; i < binary.length; i++) {
|
|
240
|
+
bytes[i] = binary.charCodeAt(i);
|
|
241
|
+
}
|
|
242
|
+
return bytes;
|
|
243
|
+
}
|
|
197
244
|
/**
|
|
198
245
|
* Generates a new session key.
|
|
199
246
|
* @param keyType - The key algorithm to use.
|
|
@@ -333,4 +380,23 @@ async function migrateFromLocalStorage(storage, keyType) {
|
|
|
333
380
|
return null;
|
|
334
381
|
}
|
|
335
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Scopes attribute keys to an OpenID provider.
|
|
385
|
+
*
|
|
386
|
+
* When using one-click sign-in, attributes can be scoped to the same provider
|
|
387
|
+
* so the user grants access in a single step without an additional prompt.
|
|
388
|
+
*
|
|
389
|
+
* @param params.openIdProvider - The OpenID provider the keys should be scoped to.
|
|
390
|
+
* @param params.keys - The attribute keys to scope. Defaults to `['name', 'email', 'verified_email']`.
|
|
391
|
+
* @returns The scoped attribute keys as `openid:<provider-url>:<key>`.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* scopedKeys({ openIdProvider: 'google', keys: ['email'] });
|
|
395
|
+
* // ['openid:https://accounts.google.com:email']
|
|
396
|
+
*/
|
|
397
|
+
export function scopedKeys(params) {
|
|
398
|
+
const provider = OPENID_PROVIDER_URLS[params.openIdProvider];
|
|
399
|
+
const keys = params.keys ?? DEFAULT_OPENID_SCOPE_KEYS;
|
|
400
|
+
return keys.map((key) => `openid:${provider}:${key}`);
|
|
401
|
+
}
|
|
336
402
|
//# sourceMappingURL=auth-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-client.js","sourceRoot":"","sources":["../../../src/client/auth-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAoC,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,GAE1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAA2B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAEL,UAAU,EACV,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,YAAY,GAEb,MAAM,cAAc,CAAC;AAEtB,MAAM,sBAAsB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACrD,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACvC,MAAM,oBAAoB,GAAG,sBAAsB,GAAG,gBAAgB,CAAC;AAEvE,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AAC5D,MAAM,wBAAwB,GAAG,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AC,CAAC;QAC9C,MAAM,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAEvC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mDAAmD,KAAK,EAAE,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAGxB,MAGD;IACC,MAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,yBAAyB,CAAC;IACtD,OAAO,IAAI,CAAC,GAAG,CACb,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,QAAQ,IAAI,GAAG,EAAuD,CAC1F,CAAC;AACJ,CAAC"}
|
|
@@ -36,7 +36,7 @@ export declare class IdleManager {
|
|
|
36
36
|
* on the existing instance.
|
|
37
37
|
* @param {IdleManagerOptions} options Optional configuration
|
|
38
38
|
* @see {@link IdleManagerOptions}
|
|
39
|
-
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh
|
|
39
|
+
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh sign-in, and use `Actor.agentOf(your_actor).invalidateIdentity()` to protect the user
|
|
40
40
|
* @param options.idleTimeout timeout in ms
|
|
41
41
|
* @param options.captureScroll capture scroll events
|
|
42
42
|
* @param options.scrollDebounce scroll debounce time in ms
|
|
@@ -19,7 +19,7 @@ export class IdleManager {
|
|
|
19
19
|
* on the existing instance.
|
|
20
20
|
* @param {IdleManagerOptions} options Optional configuration
|
|
21
21
|
* @see {@link IdleManagerOptions}
|
|
22
|
-
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh
|
|
22
|
+
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh sign-in, and use `Actor.agentOf(your_actor).invalidateIdentity()` to protect the user
|
|
23
23
|
* @param options.idleTimeout timeout in ms
|
|
24
24
|
* @param options.captureScroll capture scroll events
|
|
25
25
|
* @param options.scrollDebounce scroll debounce time in ms
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icp-sdk/auth",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"author": "DFINITY Stiftung <sdk@dfinity.org>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Authentication library for Internet Computer web apps",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@biomejs/biome": "^2.4.10",
|
|
46
46
|
"@icp-sdk/core": "^5.2.1",
|
|
47
|
-
"@icp-sdk/signer": "^5.2.0",
|
|
48
47
|
"fake-indexeddb": "^6.2.5",
|
|
49
48
|
"jsdom": "^27.4.0",
|
|
50
49
|
"publint": "^0.3.18",
|
|
@@ -55,6 +54,7 @@
|
|
|
55
54
|
"@icp-sdk/core": "^5"
|
|
56
55
|
},
|
|
57
56
|
"dependencies": {
|
|
57
|
+
"@icp-sdk/signer": "^5.3.0",
|
|
58
58
|
"idb": "^7.1.1"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
@@ -39,11 +39,13 @@ const KEY_STORAGE_EXPIRATION = 'ic-delegation_expiration';
|
|
|
39
39
|
|
|
40
40
|
export type OpenIdProvider = 'google' | 'apple' | 'microsoft';
|
|
41
41
|
|
|
42
|
-
const OPENID_PROVIDER_URLS
|
|
42
|
+
export const OPENID_PROVIDER_URLS = {
|
|
43
43
|
google: 'https://accounts.google.com',
|
|
44
44
|
apple: 'https://appleid.apple.com',
|
|
45
45
|
microsoft: 'https://login.microsoftonline.com/{tid}/v2.0',
|
|
46
|
-
}
|
|
46
|
+
} as const satisfies Record<OpenIdProvider, string>;
|
|
47
|
+
|
|
48
|
+
const DEFAULT_OPENID_SCOPE_KEYS = ['name', 'email', 'verified_email'] as const;
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Options for creating an {@link AuthClient}.
|
|
@@ -61,7 +63,7 @@ export interface AuthClientCreateOptions {
|
|
|
61
63
|
storage?: AuthClientStorage;
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
|
-
* Type of session key to generate on each
|
|
66
|
+
* Type of session key to generate on each sign-in.
|
|
65
67
|
*
|
|
66
68
|
* Use `'Ed25519'` when your storage provider does not support `CryptoKey`.
|
|
67
69
|
* @default 'ECDSA'
|
|
@@ -114,14 +116,10 @@ export interface IdleOptions extends IdleManagerOptions {
|
|
|
114
116
|
disableDefaultIdleCallback?: boolean;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
export type OnSuccessFunc = () => void | Promise<void>;
|
|
118
|
-
|
|
119
|
-
export type OnErrorFunc = (error?: string) => void | Promise<void>;
|
|
120
|
-
|
|
121
119
|
/**
|
|
122
|
-
* Options for {@link AuthClient.
|
|
120
|
+
* Options for {@link AuthClient.signIn}.
|
|
123
121
|
*/
|
|
124
|
-
export interface
|
|
122
|
+
export interface AuthClientSignInOptions {
|
|
125
123
|
/**
|
|
126
124
|
* Maximum lifetime of the delegation in nanoseconds.
|
|
127
125
|
* @default 8 hours
|
|
@@ -132,17 +130,11 @@ export interface AuthClientLoginOptions {
|
|
|
132
130
|
* Restrict the delegation to specific canisters.
|
|
133
131
|
*/
|
|
134
132
|
targets?: Principal[];
|
|
133
|
+
}
|
|
135
134
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
onSuccess?: OnSuccessFunc;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Called when login fails. When provided the error is **not** re-thrown,
|
|
143
|
-
* allowing the caller to handle it via this callback instead.
|
|
144
|
-
*/
|
|
145
|
-
onError?: OnErrorFunc;
|
|
135
|
+
export interface SignedAttributes {
|
|
136
|
+
data: Uint8Array;
|
|
137
|
+
signature: Uint8Array;
|
|
146
138
|
}
|
|
147
139
|
|
|
148
140
|
/**
|
|
@@ -151,13 +143,9 @@ export interface AuthClientLoginOptions {
|
|
|
151
143
|
* @example
|
|
152
144
|
* const authClient = new AuthClient();
|
|
153
145
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* await authClient.login({
|
|
159
|
-
* onSuccess: () => console.log('Logged in!'),
|
|
160
|
-
* });
|
|
146
|
+
* const identity = authClient.isAuthenticated()
|
|
147
|
+
* ? await authClient.getIdentity()
|
|
148
|
+
* : await authClient.signIn();
|
|
161
149
|
*/
|
|
162
150
|
export class AuthClient {
|
|
163
151
|
#identity: Identity | PartialIdentity = new AnonymousIdentity();
|
|
@@ -216,65 +204,95 @@ export class AuthClient {
|
|
|
216
204
|
}
|
|
217
205
|
|
|
218
206
|
/**
|
|
219
|
-
* Opens the identity provider
|
|
207
|
+
* Opens the identity provider, requests a delegation, and returns the authenticated identity.
|
|
220
208
|
*
|
|
221
|
-
* @param options -
|
|
209
|
+
* @param options - Sign-in options.
|
|
222
210
|
* @param options.maxTimeToLive - Maximum lifetime of the delegation in nanoseconds.
|
|
223
211
|
* @param options.targets - Restrict the delegation to specific canisters.
|
|
224
|
-
* @
|
|
225
|
-
* @
|
|
226
|
-
* @throws When authentication fails and no `onError` callback is provided.
|
|
212
|
+
* @returns The authenticated identity.
|
|
213
|
+
* @throws When authentication fails.
|
|
227
214
|
*
|
|
228
215
|
* @example
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
216
|
+
* try {
|
|
217
|
+
* const identity = await authClient.signIn();
|
|
218
|
+
* } catch (error) {
|
|
219
|
+
* console.error('Sign-in failed:', error);
|
|
220
|
+
* }
|
|
233
221
|
*/
|
|
234
|
-
async
|
|
235
|
-
|
|
236
|
-
await this.#signer.openChannel();
|
|
222
|
+
async signIn(options?: AuthClientSignInOptions): Promise<Identity> {
|
|
223
|
+
await this.#signer.openChannel();
|
|
237
224
|
|
|
238
|
-
|
|
225
|
+
const maxTimeToLive = options?.maxTimeToLive ?? DEFAULT_MAX_TIME_TO_LIVE;
|
|
239
226
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
227
|
+
// Fresh key per sign-in so each session has its own cryptographic identity.
|
|
228
|
+
const key =
|
|
229
|
+
this.#options.identity ?? (await generateKey(this.#options.keyType ?? ECDSA_KEY_LABEL));
|
|
243
230
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
231
|
+
const delegationChain = await this.#signer.requestDelegation({
|
|
232
|
+
publicKey: key.getPublicKey(),
|
|
233
|
+
targets: options?.targets,
|
|
234
|
+
maxTimeToLive,
|
|
235
|
+
});
|
|
249
236
|
|
|
250
|
-
|
|
237
|
+
this.#chain = delegationChain;
|
|
251
238
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
239
|
+
// PartialIdentity only has the public key — no signing capability.
|
|
240
|
+
if ('toDer' in key) {
|
|
241
|
+
this.#identity = PartialDelegationIdentity.fromDelegation(key, this.#chain);
|
|
242
|
+
} else {
|
|
243
|
+
this.#identity = DelegationIdentity.fromDelegation(key, this.#chain);
|
|
244
|
+
}
|
|
258
245
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
246
|
+
const idleOptions = this.#options?.idleOptions;
|
|
247
|
+
if (!this.idleManager && !idleOptions?.disableIdle) {
|
|
248
|
+
this.idleManager = IdleManager.create(idleOptions);
|
|
249
|
+
this.#registerDefaultIdleCallback();
|
|
250
|
+
}
|
|
264
251
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
252
|
+
// Persist so the session survives page reloads.
|
|
253
|
+
await persistChain(this.#storage, this.#chain);
|
|
254
|
+
await persistKey(this.#storage, key);
|
|
255
|
+
|
|
256
|
+
return this.#identity;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Requests signed identity attributes from the identity provider.
|
|
261
|
+
*
|
|
262
|
+
* @param params - Request parameters.
|
|
263
|
+
* @param params.keys - Attribute keys to request (e.g. `['email', 'name']`).
|
|
264
|
+
* @param params.nonce - 32-byte nonce issued by the RP canister.
|
|
265
|
+
* @returns Signed attribute data and signature.
|
|
266
|
+
* @throws When the identity provider returns an error or an invalid response.
|
|
267
|
+
*/
|
|
268
|
+
async requestAttributes(params: {
|
|
269
|
+
keys: string[];
|
|
270
|
+
nonce: Uint8Array;
|
|
271
|
+
}): Promise<SignedAttributes> {
|
|
272
|
+
const nonceBytes = params.nonce;
|
|
273
|
+
|
|
274
|
+
const response = await this.#signer.sendRequest({
|
|
275
|
+
jsonrpc: '2.0',
|
|
276
|
+
method: 'ii-icrc3-attributes',
|
|
277
|
+
params: { keys: params.keys, nonce: toBase64(nonceBytes) },
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
if ('error' in response) {
|
|
281
|
+
throw new Error(response.error.message);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const result = response.result as Record<string, unknown> | undefined;
|
|
285
|
+
if (typeof result?.data !== 'string' || typeof result?.signature !== 'string') {
|
|
286
|
+
throw new Error('Invalid response: missing data or signature');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
return {
|
|
291
|
+
data: fromBase64(result.data),
|
|
292
|
+
signature: fromBase64(result.signature),
|
|
293
|
+
};
|
|
294
|
+
} catch (cause) {
|
|
295
|
+
throw new Error('Invalid response: data or signature is not valid base64', { cause });
|
|
278
296
|
}
|
|
279
297
|
}
|
|
280
298
|
|
|
@@ -309,7 +327,7 @@ export class AuthClient {
|
|
|
309
327
|
|
|
310
328
|
// Attempts to restore a previous session (key + delegation chain) from
|
|
311
329
|
// storage. If found and still valid, sets #identity and #chain so the
|
|
312
|
-
// client is ready to use without a new
|
|
330
|
+
// client is ready to use without a new signIn().
|
|
313
331
|
async #hydrate(): Promise<void> {
|
|
314
332
|
const key =
|
|
315
333
|
this.#options.identity ??
|
|
@@ -343,6 +361,37 @@ export class AuthClient {
|
|
|
343
361
|
}
|
|
344
362
|
}
|
|
345
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Encodes a Uint8Array to a base64 string.
|
|
366
|
+
* @param bytes - The bytes to encode.
|
|
367
|
+
*/
|
|
368
|
+
function toBase64(bytes: Uint8Array): string {
|
|
369
|
+
if ('toBase64' in bytes && typeof bytes.toBase64 === 'function') {
|
|
370
|
+
return bytes.toBase64();
|
|
371
|
+
}
|
|
372
|
+
let binary = '';
|
|
373
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
374
|
+
binary += String.fromCharCode(bytes[i]);
|
|
375
|
+
}
|
|
376
|
+
return globalThis.btoa(binary);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Decodes a base64 string to a Uint8Array.
|
|
381
|
+
* @param str - The base64-encoded string.
|
|
382
|
+
*/
|
|
383
|
+
function fromBase64(str: string): Uint8Array {
|
|
384
|
+
if ('fromBase64' in Uint8Array && typeof Uint8Array.fromBase64 === 'function') {
|
|
385
|
+
return Uint8Array.fromBase64(str);
|
|
386
|
+
}
|
|
387
|
+
const binary = globalThis.atob(str);
|
|
388
|
+
const bytes = new Uint8Array(binary.length);
|
|
389
|
+
for (let i = 0; i < binary.length; i++) {
|
|
390
|
+
bytes[i] = binary.charCodeAt(i);
|
|
391
|
+
}
|
|
392
|
+
return bytes;
|
|
393
|
+
}
|
|
394
|
+
|
|
346
395
|
/**
|
|
347
396
|
* Generates a new session key.
|
|
348
397
|
* @param keyType - The key algorithm to use.
|
|
@@ -496,3 +545,31 @@ async function migrateFromLocalStorage(
|
|
|
496
545
|
return null;
|
|
497
546
|
}
|
|
498
547
|
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Scopes attribute keys to an OpenID provider.
|
|
551
|
+
*
|
|
552
|
+
* When using one-click sign-in, attributes can be scoped to the same provider
|
|
553
|
+
* so the user grants access in a single step without an additional prompt.
|
|
554
|
+
*
|
|
555
|
+
* @param params.openIdProvider - The OpenID provider the keys should be scoped to.
|
|
556
|
+
* @param params.keys - The attribute keys to scope. Defaults to `['name', 'email', 'verified_email']`.
|
|
557
|
+
* @returns The scoped attribute keys as `openid:<provider-url>:<key>`.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* scopedKeys({ openIdProvider: 'google', keys: ['email'] });
|
|
561
|
+
* // ['openid:https://accounts.google.com:email']
|
|
562
|
+
*/
|
|
563
|
+
export function scopedKeys<
|
|
564
|
+
P extends keyof typeof OPENID_PROVIDER_URLS,
|
|
565
|
+
K extends string = (typeof DEFAULT_OPENID_SCOPE_KEYS)[number],
|
|
566
|
+
>(params: {
|
|
567
|
+
openIdProvider: P;
|
|
568
|
+
keys?: readonly K[];
|
|
569
|
+
}): `openid:${(typeof OPENID_PROVIDER_URLS)[P]}:${K}`[] {
|
|
570
|
+
const provider = OPENID_PROVIDER_URLS[params.openIdProvider];
|
|
571
|
+
const keys = params.keys ?? DEFAULT_OPENID_SCOPE_KEYS;
|
|
572
|
+
return keys.map(
|
|
573
|
+
(key) => `openid:${provider}:${key}` as `openid:${(typeof OPENID_PROVIDER_URLS)[P]}:${K}`,
|
|
574
|
+
);
|
|
575
|
+
}
|
|
@@ -46,7 +46,7 @@ export class IdleManager {
|
|
|
46
46
|
* on the existing instance.
|
|
47
47
|
* @param {IdleManagerOptions} options Optional configuration
|
|
48
48
|
* @see {@link IdleManagerOptions}
|
|
49
|
-
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh
|
|
49
|
+
* @param options.onIdle Callback once user has been idle. Use to prompt for fresh sign-in, and use `Actor.agentOf(your_actor).invalidateIdentity()` to protect the user
|
|
50
50
|
* @param options.idleTimeout timeout in ms
|
|
51
51
|
* @param options.captureScroll capture scroll events
|
|
52
52
|
* @param options.scrollDebounce scroll debounce time in ms
|