@octap/browser-sdk 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +32 -19
- package/dist/auth.d.ts +54 -30
- package/dist/auth.js +111 -101
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/session-store.d.ts +3 -3
- package/dist/session-store.js +2 -2
- package/dist/session-store.js.map +1 -1
- package/dist/sign-in-popup.d.ts +21 -0
- package/dist/sign-in-popup.js +75 -0
- package/dist/sign-in-popup.js.map +1 -0
- package/dist/zklogin-signer.d.ts +6 -14
- package/dist/zklogin-signer.js +5 -64
- package/dist/zklogin-signer.js.map +1 -1
- package/package.json +4 -2
- package/dist/client.d.ts +0 -48
- package/dist/client.js +0 -110
- package/dist/client.js.map +0 -1
- package/dist/google-provider.d.ts +0 -13
- package/dist/google-provider.js +0 -104
- package/dist/google-provider.js.map +0 -1
package/dist/google-provider.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { OctapAuthError } from './errors.js';
|
|
2
|
-
const SCRIPT_URL = 'https://accounts.google.com/gsi/client';
|
|
3
|
-
const SCRIPT_TIMEOUT_MS = 20_000;
|
|
4
|
-
/** A credential can arrive just after the popup closes, so wait before calling it a cancellation. */
|
|
5
|
-
const CANCEL_GRACE_MS = 1_500;
|
|
6
|
-
const CANCEL_POLL_MS = 250;
|
|
7
|
-
const CANCEL_WATCH_LIMIT_MS = 5 * 60_000;
|
|
8
|
-
let loading;
|
|
9
|
-
function loadGoogleIdentity() {
|
|
10
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
11
|
-
return Promise.reject(new OctapAuthError('provider-unavailable', 'Google sign-in needs a browser.'));
|
|
12
|
-
}
|
|
13
|
-
const loaded = window.google?.accounts?.id;
|
|
14
|
-
if (loaded)
|
|
15
|
-
return Promise.resolve(loaded);
|
|
16
|
-
if (loading)
|
|
17
|
-
return loading;
|
|
18
|
-
loading = new Promise((resolve, reject) => {
|
|
19
|
-
const script = document.createElement('script');
|
|
20
|
-
script.src = SCRIPT_URL;
|
|
21
|
-
script.async = true;
|
|
22
|
-
const fail = () => {
|
|
23
|
-
window.clearTimeout(timer);
|
|
24
|
-
script.remove();
|
|
25
|
-
loading = undefined;
|
|
26
|
-
reject(new OctapAuthError('provider-unavailable', 'Google sign-in could not load.'));
|
|
27
|
-
};
|
|
28
|
-
const timer = window.setTimeout(fail, SCRIPT_TIMEOUT_MS);
|
|
29
|
-
script.onerror = fail;
|
|
30
|
-
script.onload = () => {
|
|
31
|
-
const google = window.google?.accounts?.id;
|
|
32
|
-
if (!google) {
|
|
33
|
-
fail();
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
window.clearTimeout(timer);
|
|
37
|
-
resolve(google);
|
|
38
|
-
};
|
|
39
|
-
document.head.appendChild(script);
|
|
40
|
-
});
|
|
41
|
-
return loading;
|
|
42
|
-
}
|
|
43
|
-
export function createGoogleProvider(clientId, buttonOptions = {}) {
|
|
44
|
-
let google;
|
|
45
|
-
let stopWatching;
|
|
46
|
-
return {
|
|
47
|
-
async render(element, nonce, handlers) {
|
|
48
|
-
google = await loadGoogleIdentity();
|
|
49
|
-
google.initialize({
|
|
50
|
-
client_id: clientId,
|
|
51
|
-
auto_select: false,
|
|
52
|
-
nonce,
|
|
53
|
-
callback: ({ credential }) => {
|
|
54
|
-
stopWatching?.();
|
|
55
|
-
handlers.onIdToken(credential);
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
google.renderButton(element, {
|
|
59
|
-
theme: 'outline',
|
|
60
|
-
size: 'large',
|
|
61
|
-
...buttonOptions,
|
|
62
|
-
click_listener: () => {
|
|
63
|
-
stopWatching?.();
|
|
64
|
-
stopWatching = watchForCancel(handlers.onCanceled);
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
signOut() {
|
|
69
|
-
stopWatching?.();
|
|
70
|
-
google?.disableAutoSelect();
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Google's button reports no cancellation. Its popup takes focus from this document and gives it back
|
|
76
|
-
* when it closes, so focus returning with no credential after a short wait means it was closed. This
|
|
77
|
-
* polls because Google's button is a cross-origin iframe, which makes `blur` and `focus` events on the
|
|
78
|
-
* window fire unreliably. A customer who clicks back while the popup is open also looks like this,
|
|
79
|
-
* and a credential arriving afterwards still completes the sign-in.
|
|
80
|
-
*/
|
|
81
|
-
function watchForCancel(onCanceled) {
|
|
82
|
-
const startedAt = Date.now();
|
|
83
|
-
let popupSeen = false;
|
|
84
|
-
let focusedSince;
|
|
85
|
-
const timer = window.setInterval(() => {
|
|
86
|
-
if (Date.now() - startedAt >= CANCEL_WATCH_LIMIT_MS) {
|
|
87
|
-
stop();
|
|
88
|
-
}
|
|
89
|
-
else if (!document.hasFocus()) {
|
|
90
|
-
popupSeen = true;
|
|
91
|
-
focusedSince = undefined;
|
|
92
|
-
}
|
|
93
|
-
else if (popupSeen) {
|
|
94
|
-
focusedSince ??= Date.now();
|
|
95
|
-
if (Date.now() - focusedSince >= CANCEL_GRACE_MS) {
|
|
96
|
-
stop();
|
|
97
|
-
onCanceled();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, CANCEL_POLL_MS);
|
|
101
|
-
const stop = () => window.clearInterval(timer);
|
|
102
|
-
return stop;
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=google-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"google-provider.js","sourceRoot":"","sources":["../src/google-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA6B7C,MAAM,UAAU,GAAG,wCAAwC,CAAC;AAC5D,MAAM,iBAAiB,GAAG,MAAM,CA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