@pelican-identity/auth-core 1.2.47 → 1.2.48
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 +11 -11
- package/dist/engine/engine.d.ts.map +1 -0
- package/dist/engine/engine.js +462 -0
- package/dist/engine/engine.js.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types/types.d.ts +113 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utilities/stateMachine.d.ts.map +1 -0
- package/dist/utilities/transport.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,17 +59,17 @@ const cleanup = createPelicanAuth("container-id", {
|
|
|
59
59
|
|
|
60
60
|
The `createPelicanAuth` function initializes the Pelican UI inside a target DOM element.
|
|
61
61
|
|
|
62
|
-
| Option | Type
|
|
63
|
-
| ---------------- |
|
|
64
|
-
| `publicKey` | `string`
|
|
65
|
-
| `projectId` | `string`
|
|
66
|
-
| `authType` | `AuthType`
|
|
67
|
-
| `onSuccess` | `Function`
|
|
68
|
-
| `onError` | `Function`
|
|
69
|
-
| `onClose` | `Function`
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
62
|
+
| Option | Type | Required | Description |
|
|
63
|
+
| ---------------- | -------------------------- | -------- | ------------------------------------------------------------------------- |
|
|
64
|
+
| `publicKey` | `string` | ✅ | Business public key from Pelican dashboard |
|
|
65
|
+
| `projectId` | `string` | ✅ | Project ID from Pelican dashboard |
|
|
66
|
+
| `authType` | `AuthType` | ✅ | `"signup"`, `"login"`, or `"id-verification"` |
|
|
67
|
+
| `onSuccess` | `Function` | ✅ | Callback with `IdentityResult` |
|
|
68
|
+
| `onError` | `Function` | ❌ | Callback for errors |
|
|
69
|
+
| `onClose` | `Function` | ❌ | Callback when the user closes the modal |
|
|
70
|
+
| `forceQRCode` | `boolean (default: false)` | Optional | Always show QR code instead of deep link |
|
|
71
|
+
| `continuousMode` | `boolean (default: false)` | Optional | Automatically restart auth after completion |
|
|
72
|
+
| `disableWebAuth` | `boolean (default: false)` | Optional | Disable web authentication, useful for phyiscal access control and kiosks |
|
|
73
73
|
|
|
74
74
|
---
|
|
75
75
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EAGpB,MAAM,gBAAgB,CAAC;AAgBxB,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;AAQxC,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAEnD,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAa;IAErC,OAAO,CAAC,iBAAiB,CAAC,CAAa;IACvC,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,aAAa,CAA8C;IAEnE,OAAO,CAAC,SAAS,CAEV;IAEP,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;gBAEzC,MAAM,EAAE,iBAAiB;IAiBrC,EAAE,CAAC,CAAC,SAAS,MAAM,mBAAmB,EACpC,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAOhC,KAAK;IA2CX,IAAI;IAIJ,WAAW;IAiIX,OAAO;IAQP,YAAY;IAQZ,kBAAkB;IAOlB,OAAO,CAAC,kBAAkB;YAeZ,kBAAkB;IAuBhC,OAAO,CAAC,sBAAsB;IA4B9B,OAAO,CAAC,iBAAiB;YAqCX,iBAAiB;IAYxB,YAAY;IA6BnB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,cAAc,CAA8C;YAEtD,YAAY;IAsE1B,OAAO,CAAC,WAAW;YASL,UAAU;YAkBV,YAAY;IAe1B,OAAO,CAAC,wBAAwB;IAuBhC,OAAO,CAAC,wBAAwB;YASlB,aAAa;IAkB3B,OAAO,CAAC,SAAS;IA6BjB,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,IAAI;CAIb"}
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import CryptoService from "../utilities/crypto";
|
|
2
|
+
import QRCode from "qrcode";
|
|
3
|
+
import { storeAuthSession, getAuthSession, clearAuthSession, } from "../utilities/storage";
|
|
4
|
+
import { StateMachine } from "../utilities/stateMachine";
|
|
5
|
+
import { Transport } from "../utilities/transport";
|
|
6
|
+
import { APPLE_APP_STORE_URL, BASEURL, FALLBACK_URL, PLAY_STORE_URL, } from "../constants";
|
|
7
|
+
export class PelicanAuthentication {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.crypto = new CryptoService();
|
|
10
|
+
this.stateMachine = new StateMachine();
|
|
11
|
+
this.sessionId = "";
|
|
12
|
+
this.sessionKey = null;
|
|
13
|
+
this.MAX_POLLING_DURATION = 2 * 60 * 1000;
|
|
14
|
+
this.INITIAL_DELAY = 2000;
|
|
15
|
+
this.MAX_DELAY = 10000;
|
|
16
|
+
this.pollingStartTime = 0;
|
|
17
|
+
this.useWebSocket = true;
|
|
18
|
+
this.deeplinkUrl = null;
|
|
19
|
+
this.fallbackTimer = null;
|
|
20
|
+
this.listeners = {};
|
|
21
|
+
this.pollingTimeout = null;
|
|
22
|
+
if (!config.publicKey)
|
|
23
|
+
throw new Error("Missing publicKey");
|
|
24
|
+
if (!config.projectId)
|
|
25
|
+
throw new Error("Missing projectId");
|
|
26
|
+
if (!config.authType)
|
|
27
|
+
throw new Error("Missing authType");
|
|
28
|
+
this.config = {
|
|
29
|
+
continuousMode: false,
|
|
30
|
+
forceQRCode: false,
|
|
31
|
+
disableWebAuth: false,
|
|
32
|
+
...config,
|
|
33
|
+
};
|
|
34
|
+
this.stateMachine.subscribe((s) => this.emit("state", s));
|
|
35
|
+
}
|
|
36
|
+
on(event, cb) {
|
|
37
|
+
var _a;
|
|
38
|
+
(_a = this.listeners)[event] ?? (_a[event] = new Set());
|
|
39
|
+
this.listeners[event].add(cb);
|
|
40
|
+
return () => this.listeners[event].delete(cb);
|
|
41
|
+
}
|
|
42
|
+
async start() {
|
|
43
|
+
if (this.config.authType !== "id-verification" &&
|
|
44
|
+
this.config.authType !== "signup" &&
|
|
45
|
+
this.config.authType !== "login") {
|
|
46
|
+
this.fail(new Error("Invalid authType"));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!this.config.projectId) {
|
|
50
|
+
this.fail(new Error("Missing projectId"));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!this.config.publicKey) {
|
|
54
|
+
this.fail(new Error("Missing publicKey"));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (this.stateMachine.current !== "idle")
|
|
58
|
+
return;
|
|
59
|
+
this.resetSession();
|
|
60
|
+
clearAuthSession();
|
|
61
|
+
this.stateMachine.transition("initializing");
|
|
62
|
+
try {
|
|
63
|
+
this.sessionKey = this.crypto.generateSymmetricKey();
|
|
64
|
+
this.sessionId = crypto.randomUUID() + crypto.randomUUID();
|
|
65
|
+
this.useWebSocket = this.shouldUseWebSocket();
|
|
66
|
+
if (this.useWebSocket) {
|
|
67
|
+
await this.startWebSocketFlow();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await this.startDeepLinkFlow();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.fail(err instanceof Error ? err : new Error("Start failed"));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
this.terminate(false);
|
|
79
|
+
}
|
|
80
|
+
openWebAuth() {
|
|
81
|
+
if (this.config.disableWebAuth || this.config.forceQRCode) {
|
|
82
|
+
this.fail(new Error("Web authentication is disabled"));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!this.sessionKey || !this.sessionId) {
|
|
86
|
+
this.fail(new Error("No active session. Call start() before openWebAuth()."));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const openerOrigin = window.location.origin;
|
|
90
|
+
const urlParams = new URLSearchParams({
|
|
91
|
+
projectId: this.config.projectId,
|
|
92
|
+
publicKey: this.config.publicKey,
|
|
93
|
+
authType: this.config.authType,
|
|
94
|
+
sessionId: this.sessionId,
|
|
95
|
+
sessionKey: this.sessionKey,
|
|
96
|
+
origin: openerOrigin,
|
|
97
|
+
});
|
|
98
|
+
const authUrl = `https://vault.pelicanidentity.com/auth?${urlParams.toString()}`;
|
|
99
|
+
const authWindow = window.open(authUrl, "pelican-auth", "width=480,height=640,left=400,top=100,resizable=no,scrollbars=no") ?? window.open(authUrl, "_blank");
|
|
100
|
+
if (!authWindow) {
|
|
101
|
+
this.fail(new Error("Unable to open authentication window. Please allow popups for this site and try again."));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.detachVisibilityRecovery();
|
|
105
|
+
this.transport?.close();
|
|
106
|
+
this.transport = undefined;
|
|
107
|
+
authWindow.focus();
|
|
108
|
+
this.stateMachine.transition("awaiting-pair");
|
|
109
|
+
const cleanup = () => {
|
|
110
|
+
window.removeEventListener("message", handleMessage);
|
|
111
|
+
clearInterval(closedPoller);
|
|
112
|
+
};
|
|
113
|
+
const handleMessage = (event) => {
|
|
114
|
+
if (event.origin !== "https://vault.pelicanidentity.com")
|
|
115
|
+
return;
|
|
116
|
+
if (event.source !== authWindow)
|
|
117
|
+
return;
|
|
118
|
+
const { type, payload } = event.data ?? {};
|
|
119
|
+
if (type === "pelican-auth-success") {
|
|
120
|
+
console.log("Web auth success");
|
|
121
|
+
cleanup();
|
|
122
|
+
if (!payload?.cipher || !payload?.nonce) {
|
|
123
|
+
this.fail(new Error("Invalid web auth payload"));
|
|
124
|
+
this.restartIfContinuous();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const decrypted = this.crypto.decryptSymmetric({
|
|
129
|
+
encrypted: { cipher: payload.cipher, nonce: payload.nonce },
|
|
130
|
+
keyString: this.sessionKey,
|
|
131
|
+
});
|
|
132
|
+
if (!decrypted) {
|
|
133
|
+
this.fail(new Error("Failed to decrypt web auth response"));
|
|
134
|
+
this.restartIfContinuous();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const result = JSON.parse(decrypted);
|
|
138
|
+
this.emit("success", result);
|
|
139
|
+
this.stateMachine.transition("authenticated");
|
|
140
|
+
this.restartIfContinuous();
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
this.fail(new Error("Failed to decrypt web auth response"));
|
|
144
|
+
this.restartIfContinuous();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (type === "pelican-auth-cancelled") {
|
|
148
|
+
cleanup();
|
|
149
|
+
this.fail(new Error("Authentication cancelled"));
|
|
150
|
+
this.restartIfContinuous();
|
|
151
|
+
}
|
|
152
|
+
if (type === "pelican-auth-error") {
|
|
153
|
+
cleanup();
|
|
154
|
+
this.fail(new Error(payload?.message ?? "Web auth failed"));
|
|
155
|
+
this.restartIfContinuous();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
window.addEventListener("message", handleMessage);
|
|
159
|
+
const closedPoller = setInterval(() => {
|
|
160
|
+
if (!authWindow.closed)
|
|
161
|
+
return;
|
|
162
|
+
cleanup();
|
|
163
|
+
if (!["authenticated", "confirmed", "error"].includes(this.stateMachine.current)) {
|
|
164
|
+
this.fail(new Error("Authentication window closed"));
|
|
165
|
+
this.restartIfContinuous();
|
|
166
|
+
}
|
|
167
|
+
}, 500);
|
|
168
|
+
}
|
|
169
|
+
destroy() {
|
|
170
|
+
this.detachVisibilityRecovery();
|
|
171
|
+
this.clearBackupCheck();
|
|
172
|
+
this.transport?.close();
|
|
173
|
+
this.transport = undefined;
|
|
174
|
+
this.listeners = {};
|
|
175
|
+
}
|
|
176
|
+
useQrInstead() {
|
|
177
|
+
this.useWebSocket = true;
|
|
178
|
+
this.emit("deeplink", "");
|
|
179
|
+
this.stateMachine.transition("initializing");
|
|
180
|
+
this.startWebSocketFlow();
|
|
181
|
+
}
|
|
182
|
+
useDeepLinkInstead() {
|
|
183
|
+
this.useWebSocket = false;
|
|
184
|
+
this.stateMachine.transition("initializing");
|
|
185
|
+
this.startDeepLinkFlow();
|
|
186
|
+
}
|
|
187
|
+
shouldUseWebSocket() {
|
|
188
|
+
const userAgent = navigator.userAgent;
|
|
189
|
+
const isTablet = /(iPad|Android(?!.*Mobile))/i.test(userAgent);
|
|
190
|
+
const isMobile = /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
|
|
191
|
+
const useWebSocket = isMobile && !isTablet;
|
|
192
|
+
return this.config.forceQRCode || !useWebSocket;
|
|
193
|
+
}
|
|
194
|
+
async startWebSocketFlow() {
|
|
195
|
+
const { relayUrl, deeplinkUrl } = await this.fetchRelayUrl();
|
|
196
|
+
this.transport = new Transport({
|
|
197
|
+
onOpen: () => {
|
|
198
|
+
this.transport.send({
|
|
199
|
+
type: "register",
|
|
200
|
+
sessionID: this.sessionId,
|
|
201
|
+
...this.config,
|
|
202
|
+
});
|
|
203
|
+
this.stateMachine.transition("awaiting-pair");
|
|
204
|
+
},
|
|
205
|
+
onMessage: (msg) => this.handleWebSocketMessage(msg),
|
|
206
|
+
onError: (err) => {
|
|
207
|
+
console.error("WebSocket error:", err);
|
|
208
|
+
this.fail(new Error("WebSocket connection failed"));
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
this.transport.connect(relayUrl);
|
|
212
|
+
await this.emitQRCode(deeplinkUrl);
|
|
213
|
+
}
|
|
214
|
+
handleWebSocketMessage(msg) {
|
|
215
|
+
switch (msg.type) {
|
|
216
|
+
case "paired":
|
|
217
|
+
this.stateMachine.transition("paired");
|
|
218
|
+
this.transport.send({
|
|
219
|
+
type: "authenticate",
|
|
220
|
+
sessionID: this.sessionId,
|
|
221
|
+
...this.config,
|
|
222
|
+
url: window.location.href,
|
|
223
|
+
});
|
|
224
|
+
return;
|
|
225
|
+
case "phone-auth-success":
|
|
226
|
+
this.handleAuthSuccess(msg);
|
|
227
|
+
return;
|
|
228
|
+
case "phone-terminated":
|
|
229
|
+
this.fail(new Error("Authentication cancelled on device"));
|
|
230
|
+
this.restartIfContinuous();
|
|
231
|
+
return;
|
|
232
|
+
case "confirmed":
|
|
233
|
+
this.terminate(true);
|
|
234
|
+
this.restartIfContinuous();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
handleAuthSuccess(msg) {
|
|
239
|
+
if (!this.sessionKey || !msg.cipher || !msg.nonce) {
|
|
240
|
+
this.fail(new Error("Invalid authentication payload"));
|
|
241
|
+
this.restartIfContinuous();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const decrypted = this.crypto.decryptSymmetric({
|
|
246
|
+
encrypted: { cipher: msg.cipher, nonce: msg.nonce },
|
|
247
|
+
keyString: this.sessionKey,
|
|
248
|
+
});
|
|
249
|
+
if (!decrypted) {
|
|
250
|
+
this.fail(new Error("Invalid authentication data"));
|
|
251
|
+
this.restartIfContinuous();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const result = JSON.parse(decrypted);
|
|
255
|
+
this.emit("success", result);
|
|
256
|
+
this.stateMachine.transition("authenticated");
|
|
257
|
+
this.transport?.send({
|
|
258
|
+
type: "confirm",
|
|
259
|
+
sessionID: this.sessionId,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
this.fail(new Error("Failed to decrypt authentication data"));
|
|
264
|
+
this.restartIfContinuous();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async startDeepLinkFlow() {
|
|
268
|
+
const { deeplinkUrl } = await this.fetchRelayUrl();
|
|
269
|
+
if (this.sessionKey) {
|
|
270
|
+
storeAuthSession(this.sessionId, this.sessionKey, 10 * 60000);
|
|
271
|
+
}
|
|
272
|
+
await this.emitDeepLink(deeplinkUrl);
|
|
273
|
+
this.stateMachine.transition("awaiting-pair");
|
|
274
|
+
}
|
|
275
|
+
openDeepLink() {
|
|
276
|
+
if (!this.deeplinkUrl) {
|
|
277
|
+
this.fail(new Error("Deep link not found"));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const userAgent = navigator.userAgent;
|
|
281
|
+
let fallbackUrl = FALLBACK_URL;
|
|
282
|
+
if (/iPad|iPhone|iPod/.test(userAgent)) {
|
|
283
|
+
fallbackUrl = APPLE_APP_STORE_URL;
|
|
284
|
+
}
|
|
285
|
+
else if (/android/i.test(userAgent)) {
|
|
286
|
+
fallbackUrl = PLAY_STORE_URL;
|
|
287
|
+
}
|
|
288
|
+
const start = Date.now();
|
|
289
|
+
this.fallbackTimer = setTimeout(() => {
|
|
290
|
+
if (Date.now() - start < 3500) {
|
|
291
|
+
window.location.href = fallbackUrl;
|
|
292
|
+
this.fail(new Error("Pelican Vault not installed on your device"));
|
|
293
|
+
setTimeout(() => {
|
|
294
|
+
this.terminate(false);
|
|
295
|
+
}, 2000);
|
|
296
|
+
}
|
|
297
|
+
}, 3000);
|
|
298
|
+
this.attachVisibilityRecovery();
|
|
299
|
+
window.location.href = this.deeplinkUrl;
|
|
300
|
+
}
|
|
301
|
+
clearBackupCheck() {
|
|
302
|
+
if (this.backupCheckTimeout) {
|
|
303
|
+
clearTimeout(this.backupCheckTimeout);
|
|
304
|
+
this.backupCheckTimeout = undefined;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async checkSession() {
|
|
308
|
+
const cached = getAuthSession();
|
|
309
|
+
if (!cached) {
|
|
310
|
+
this.fail(new Error("Authentication session not found"));
|
|
311
|
+
this.restartIfContinuous();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this.stopPolling();
|
|
315
|
+
this.pollingStartTime = Date.now();
|
|
316
|
+
this.stateMachine.transition("awaiting-auth");
|
|
317
|
+
let currentDelay = this.INITIAL_DELAY;
|
|
318
|
+
const performCheck = async () => {
|
|
319
|
+
if (Date.now() - this.pollingStartTime > this.MAX_POLLING_DURATION) {
|
|
320
|
+
this.stopPolling();
|
|
321
|
+
this.fail(new Error("Authentication timed out. Please try again."));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const res = await fetch(`${BASEURL}/session?session_id=${cached.sessionId}`);
|
|
326
|
+
if (res.ok) {
|
|
327
|
+
const data = await res.json();
|
|
328
|
+
const decrypted = this.crypto.decryptSymmetric({
|
|
329
|
+
encrypted: { cipher: data.cipher, nonce: data.nonce },
|
|
330
|
+
keyString: cached.sessionKey,
|
|
331
|
+
});
|
|
332
|
+
if (!decrypted) {
|
|
333
|
+
this.stopPolling();
|
|
334
|
+
this.fail(new Error("Failed to decrypt session"));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
this.stopPolling();
|
|
338
|
+
this.clearBackupCheck();
|
|
339
|
+
clearAuthSession();
|
|
340
|
+
const result = JSON.parse(decrypted);
|
|
341
|
+
this.emit("success", result);
|
|
342
|
+
this.stateMachine.transition("authenticated");
|
|
343
|
+
this.restartIfContinuous();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
console.debug("Session not ready yet...");
|
|
347
|
+
}
|
|
348
|
+
catch (err) {
|
|
349
|
+
console.debug("Network error during session check, retrying:", err);
|
|
350
|
+
}
|
|
351
|
+
if (this.stateMachine.current === "awaiting-auth") {
|
|
352
|
+
this.pollingTimeout = setTimeout(() => {
|
|
353
|
+
currentDelay = Math.min(currentDelay * 1.5, this.MAX_DELAY);
|
|
354
|
+
performCheck();
|
|
355
|
+
}, currentDelay);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
await performCheck();
|
|
359
|
+
}
|
|
360
|
+
stopPolling() {
|
|
361
|
+
if (this.pollingTimeout) {
|
|
362
|
+
clearTimeout(this.pollingTimeout);
|
|
363
|
+
this.pollingTimeout = null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async emitQRCode(deeplinkUrl) {
|
|
367
|
+
const embeddedUrl = `${deeplinkUrl}?sessionID=${encodeURIComponent(this.sessionId)}&sessionKey=${encodeURIComponent(this.sessionKey)}&publicKey=${encodeURIComponent(this.config.publicKey)}&authType=${this.config.authType}&projectId=${encodeURIComponent(this.config.projectId)}`;
|
|
368
|
+
const qr = await QRCode.toDataURL(embeddedUrl, {
|
|
369
|
+
type: "image/png",
|
|
370
|
+
scale: 3,
|
|
371
|
+
color: { light: "#ffffff", dark: "#424242ff" },
|
|
372
|
+
});
|
|
373
|
+
this.emit("qr", qr);
|
|
374
|
+
}
|
|
375
|
+
async emitDeepLink(deeplinkUrl) {
|
|
376
|
+
const deeplink = `${deeplinkUrl}?sessionID=${encodeURIComponent(this.sessionId)}&sessionKey=${encodeURIComponent(this.sessionKey)}&publicKey=${encodeURIComponent(this.config.publicKey)}&authType=${this.config.authType}&projectId=${encodeURIComponent(this.config.projectId)}`;
|
|
377
|
+
this.deeplinkUrl = deeplink;
|
|
378
|
+
this.emit("deeplink", deeplink);
|
|
379
|
+
}
|
|
380
|
+
attachVisibilityRecovery() {
|
|
381
|
+
let fired = false;
|
|
382
|
+
this.visibilityHandler = async () => {
|
|
383
|
+
if (this.fallbackTimer) {
|
|
384
|
+
clearTimeout(this.fallbackTimer);
|
|
385
|
+
this.fallbackTimer = null;
|
|
386
|
+
}
|
|
387
|
+
if (document.visibilityState !== "visible")
|
|
388
|
+
return;
|
|
389
|
+
if (this.useWebSocket)
|
|
390
|
+
return;
|
|
391
|
+
if (fired)
|
|
392
|
+
return;
|
|
393
|
+
fired = true;
|
|
394
|
+
await this.checkSession();
|
|
395
|
+
};
|
|
396
|
+
document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
397
|
+
}
|
|
398
|
+
detachVisibilityRecovery() {
|
|
399
|
+
if (this.visibilityHandler) {
|
|
400
|
+
document.removeEventListener("visibilitychange", this.visibilityHandler);
|
|
401
|
+
this.visibilityHandler = undefined;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async fetchRelayUrl() {
|
|
405
|
+
const { publicKey, projectId, authType } = this.config;
|
|
406
|
+
const res = await fetch(`${BASEURL}/relay?public_key=${publicKey}&auth_type=${authType}&project_id=${projectId}`);
|
|
407
|
+
if (!res.ok) {
|
|
408
|
+
const error = await res.text();
|
|
409
|
+
throw new Error(error);
|
|
410
|
+
}
|
|
411
|
+
const json = await res.json();
|
|
412
|
+
return { deeplinkUrl: json.deeplink_url, relayUrl: json.relay_url };
|
|
413
|
+
}
|
|
414
|
+
terminate(success) {
|
|
415
|
+
this.clearBackupCheck();
|
|
416
|
+
if (this.transport) {
|
|
417
|
+
if (!success) {
|
|
418
|
+
this.transport.send({
|
|
419
|
+
type: "client-terminated",
|
|
420
|
+
sessionID: this.sessionId,
|
|
421
|
+
projectId: this.config.projectId,
|
|
422
|
+
publicKey: this.config.publicKey,
|
|
423
|
+
authType: this.config.authType,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
this.transport.close();
|
|
427
|
+
this.transport = undefined;
|
|
428
|
+
}
|
|
429
|
+
clearAuthSession();
|
|
430
|
+
this.resetSession();
|
|
431
|
+
if (!this.config.continuousMode) {
|
|
432
|
+
this.detachVisibilityRecovery();
|
|
433
|
+
}
|
|
434
|
+
this.stateMachine.transition(success ? "confirmed" : "idle");
|
|
435
|
+
}
|
|
436
|
+
restartIfContinuous() {
|
|
437
|
+
if (this.config.continuousMode) {
|
|
438
|
+
this.stateMachine.transition("idle");
|
|
439
|
+
this.clearBackupCheck();
|
|
440
|
+
this.transport?.close();
|
|
441
|
+
this.transport = undefined;
|
|
442
|
+
setTimeout(() => {
|
|
443
|
+
this.start();
|
|
444
|
+
}, 150);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
this.stateMachine.transition("idle");
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
resetSession() {
|
|
451
|
+
this.sessionId = "";
|
|
452
|
+
this.sessionKey = null;
|
|
453
|
+
}
|
|
454
|
+
emit(event, payload) {
|
|
455
|
+
this.listeners[event]?.forEach((cb) => cb(payload));
|
|
456
|
+
}
|
|
457
|
+
fail(err) {
|
|
458
|
+
this.emit("error", err);
|
|
459
|
+
this.stateMachine.transition("error");
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAC;AAUtB,MAAM,OAA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;CACF"}
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -347,6 +347,7 @@ var PelicanAuthentication = class {
|
|
|
347
347
|
this.config = {
|
|
348
348
|
continuousMode: false,
|
|
349
349
|
forceQRCode: false,
|
|
350
|
+
disableWebAuth: false,
|
|
350
351
|
...config
|
|
351
352
|
};
|
|
352
353
|
this.stateMachine.subscribe((s) => this.emit("state", s));
|
|
@@ -392,6 +393,10 @@ var PelicanAuthentication = class {
|
|
|
392
393
|
this.terminate(false);
|
|
393
394
|
}
|
|
394
395
|
openWebAuth() {
|
|
396
|
+
if (this.config.disableWebAuth || this.config.forceQRCode) {
|
|
397
|
+
this.fail(new Error("Web authentication is disabled"));
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
395
400
|
if (!this.sessionKey || !this.sessionId) {
|
|
396
401
|
this.fail(
|
|
397
402
|
new Error("No active session. Call start() before openWebAuth().")
|