postex-auth-sdk-stage 1.0.3 → 1.0.4
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/dist/postex-auth-sdk-stage.es.js +177 -149
- package/dist/postex-auth-sdk-stage.es.js.map +1 -1
- package/dist/postex-auth-sdk-stage.iife.js +1 -1
- package/dist/postex-auth-sdk-stage.iife.js.map +1 -1
- package/dist/postex-auth-sdk-stage.umd.js +1 -1
- package/dist/postex-auth-sdk-stage.umd.js.map +1 -1
- package/package.json +1 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function
|
|
1
|
+
function O() {
|
|
2
2
|
return typeof window < "u" && typeof window.PublicKeyCredential < "u" && typeof navigator < "u" && typeof navigator.credentials < "u";
|
|
3
3
|
}
|
|
4
|
-
async function
|
|
5
|
-
if (!
|
|
4
|
+
async function j() {
|
|
5
|
+
if (!O()) return !1;
|
|
6
6
|
try {
|
|
7
7
|
return await PublicKeyCredential.isConditionalMediationAvailable?.() ?? !1;
|
|
8
8
|
} catch {
|
|
@@ -16,14 +16,14 @@ function h(o) {
|
|
|
16
16
|
t += String.fromCharCode(n[e]);
|
|
17
17
|
return btoa(t);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function f(o) {
|
|
20
20
|
if (typeof o != "string" || !o)
|
|
21
21
|
throw new Error("Invalid base64: expected non-empty string");
|
|
22
22
|
const n = o.replace(/\s/g, "").replace(/-/g, "+").replace(/_/g, "/"), t = n.length % 4, e = t > 0 ? n + "=".repeat(4 - t) : n;
|
|
23
23
|
try {
|
|
24
|
-
const
|
|
25
|
-
for (let
|
|
26
|
-
r[
|
|
24
|
+
const s = atob(e), r = new Uint8Array(s.length);
|
|
25
|
+
for (let a = 0; a < s.length; a++)
|
|
26
|
+
r[a] = s.charCodeAt(a);
|
|
27
27
|
return r.buffer;
|
|
28
28
|
} catch {
|
|
29
29
|
throw new Error(
|
|
@@ -31,35 +31,35 @@ function k(o) {
|
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function k(o) {
|
|
35
35
|
return h(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function J(o) {
|
|
38
38
|
return /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i.test(
|
|
39
39
|
o
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function L(o) {
|
|
43
43
|
const n = o.replace(/-/g, ""), t = new Uint8Array(n.length / 2);
|
|
44
44
|
for (let e = 0; e < t.length; e++)
|
|
45
45
|
t[e] = parseInt(n.substr(e * 2, 2), 16);
|
|
46
46
|
return t.buffer;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function W(o) {
|
|
49
49
|
if (!o || typeof o != "string")
|
|
50
50
|
throw new Error("Invalid input: expected non-empty string");
|
|
51
|
-
return
|
|
51
|
+
return J(o) ? L(o) : f(o);
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function S(o) {
|
|
54
54
|
return new TextEncoder().encode(o).buffer;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function H(o) {
|
|
57
57
|
return String.fromCharCode(...o);
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const Y = "xpay_webauthn", F = 1, d = "passkey_data", E = "passkey_email";
|
|
60
60
|
function p() {
|
|
61
61
|
return new Promise((o, n) => {
|
|
62
|
-
const t = indexedDB.open(
|
|
62
|
+
const t = indexedDB.open(Y, F);
|
|
63
63
|
t.onerror = () => n(t.error), t.onsuccess = () => o(t.result), t.onupgradeneeded = () => {
|
|
64
64
|
const e = t.result;
|
|
65
65
|
e.objectStoreNames.contains(d) || e.createObjectStore(d);
|
|
@@ -70,7 +70,7 @@ async function G() {
|
|
|
70
70
|
try {
|
|
71
71
|
const o = await p();
|
|
72
72
|
return new Promise((n, t) => {
|
|
73
|
-
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(
|
|
73
|
+
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(E);
|
|
74
74
|
r.onerror = () => t(r.error), r.onsuccess = () => n(r.result ?? null), e.oncomplete = () => o.close();
|
|
75
75
|
});
|
|
76
76
|
} catch {
|
|
@@ -81,8 +81,8 @@ async function M(o) {
|
|
|
81
81
|
try {
|
|
82
82
|
const n = await p();
|
|
83
83
|
return new Promise((t, e) => {
|
|
84
|
-
const
|
|
85
|
-
|
|
84
|
+
const s = n.transaction(d, "readwrite"), a = s.objectStore(d).put(o, E);
|
|
85
|
+
a.onerror = () => e(a.error), a.onsuccess = () => t(), s.oncomplete = () => n.close();
|
|
86
86
|
});
|
|
87
87
|
} catch {
|
|
88
88
|
}
|
|
@@ -91,14 +91,14 @@ async function V() {
|
|
|
91
91
|
try {
|
|
92
92
|
const o = await p();
|
|
93
93
|
return new Promise((n, t) => {
|
|
94
|
-
const e = o.transaction(d, "readwrite"), r = e.objectStore(d).delete(
|
|
94
|
+
const e = o.transaction(d, "readwrite"), r = e.objectStore(d).delete(E);
|
|
95
95
|
r.onerror = () => t(r.error), r.onsuccess = () => n(), e.oncomplete = () => o.close();
|
|
96
96
|
});
|
|
97
97
|
} catch {
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
function
|
|
100
|
+
const I = "dpop_private_key", x = "dpop_public_key_jwk";
|
|
101
|
+
function v(o) {
|
|
102
102
|
return {
|
|
103
103
|
kty: "EC",
|
|
104
104
|
crv: "P-256",
|
|
@@ -106,7 +106,7 @@ function U(o) {
|
|
|
106
106
|
y: o.y
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
async function
|
|
109
|
+
async function q(o) {
|
|
110
110
|
const n = JSON.stringify({
|
|
111
111
|
crv: o.crv,
|
|
112
112
|
kty: o.kty,
|
|
@@ -116,65 +116,65 @@ async function N(o) {
|
|
|
116
116
|
"SHA-256",
|
|
117
117
|
new TextEncoder().encode(n)
|
|
118
118
|
);
|
|
119
|
-
return
|
|
119
|
+
return k(t);
|
|
120
120
|
}
|
|
121
|
-
async function
|
|
121
|
+
async function R(o) {
|
|
122
122
|
try {
|
|
123
123
|
const n = await p();
|
|
124
124
|
return new Promise((t, e) => {
|
|
125
|
-
const
|
|
126
|
-
|
|
125
|
+
const s = n.transaction(d, "readwrite"), a = s.objectStore(d).put(o, I);
|
|
126
|
+
a.onerror = () => e(a.error), a.onsuccess = () => t(), s.oncomplete = () => n.close();
|
|
127
127
|
});
|
|
128
128
|
} catch (n) {
|
|
129
129
|
console.error("Failed to store DPoP private key:", n);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
async function
|
|
132
|
+
async function z(o) {
|
|
133
133
|
try {
|
|
134
134
|
const n = await p();
|
|
135
135
|
return new Promise((t, e) => {
|
|
136
|
-
const
|
|
137
|
-
|
|
136
|
+
const s = n.transaction(d, "readwrite"), a = s.objectStore(d).put(o, x);
|
|
137
|
+
a.onerror = () => e(a.error), a.onsuccess = () => t(), s.oncomplete = () => n.close();
|
|
138
138
|
});
|
|
139
139
|
} catch (n) {
|
|
140
140
|
console.error("Failed to store DPoP public key JWK:", n);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
async function
|
|
143
|
+
async function A() {
|
|
144
144
|
try {
|
|
145
145
|
const o = await p();
|
|
146
146
|
return new Promise((n, t) => {
|
|
147
|
-
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(
|
|
147
|
+
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(I);
|
|
148
148
|
r.onerror = () => t(r.error), r.onsuccess = () => n(r.result ?? null), e.oncomplete = () => o.close();
|
|
149
149
|
});
|
|
150
150
|
} catch {
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
async function
|
|
154
|
+
async function C() {
|
|
155
155
|
try {
|
|
156
156
|
const o = await p();
|
|
157
157
|
return new Promise((n, t) => {
|
|
158
|
-
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(
|
|
158
|
+
const e = o.transaction(d, "readonly"), r = e.objectStore(d).get(x);
|
|
159
159
|
r.onerror = () => t(r.error), r.onsuccess = () => n(r.result ?? null), e.oncomplete = () => o.close();
|
|
160
160
|
});
|
|
161
161
|
} catch {
|
|
162
162
|
return null;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
async function
|
|
165
|
+
async function $() {
|
|
166
166
|
try {
|
|
167
167
|
const o = await p();
|
|
168
168
|
return new Promise((n, t) => {
|
|
169
|
-
const e = o.transaction(d, "readwrite"),
|
|
170
|
-
|
|
169
|
+
const e = o.transaction(d, "readwrite"), s = e.objectStore(d);
|
|
170
|
+
s.delete(I), s.delete(x), e.onerror = () => t(e.error), e.oncomplete = () => {
|
|
171
171
|
o.close(), n();
|
|
172
172
|
};
|
|
173
173
|
});
|
|
174
174
|
} catch {
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
async function
|
|
177
|
+
async function P() {
|
|
178
178
|
const o = await crypto.subtle.generateKey(
|
|
179
179
|
{
|
|
180
180
|
name: "ECDSA",
|
|
@@ -183,81 +183,106 @@ async function _() {
|
|
|
183
183
|
!1,
|
|
184
184
|
// Private key is non-extractable
|
|
185
185
|
["sign", "verify"]
|
|
186
|
-
), n = await crypto.subtle.exportKey("jwk", o.publicKey), t =
|
|
187
|
-
return await
|
|
186
|
+
), n = await crypto.subtle.exportKey("jwk", o.publicKey), t = v(n), e = await q(t);
|
|
187
|
+
return await R(o.privateKey), await z(t), { publicKey: t, thumbprint: e };
|
|
188
188
|
}
|
|
189
|
-
async function
|
|
189
|
+
async function g(o, n, t) {
|
|
190
190
|
try {
|
|
191
|
-
const e = await
|
|
192
|
-
if (!e || !
|
|
191
|
+
const e = await A(), s = await C();
|
|
192
|
+
if (!e || !s) return null;
|
|
193
193
|
const r = {
|
|
194
194
|
typ: "dpop+jwt",
|
|
195
195
|
alg: "ES256",
|
|
196
|
-
jwk:
|
|
196
|
+
jwk: s
|
|
197
197
|
// Public key in JWK format
|
|
198
|
-
},
|
|
198
|
+
}, a = new URL(
|
|
199
199
|
n,
|
|
200
200
|
typeof window < "u" ? window.location.origin : void 0
|
|
201
|
-
), i = `${
|
|
201
|
+
), i = `${a.origin}${a.pathname}`, u = {
|
|
202
202
|
jti: crypto.randomUUID(),
|
|
203
203
|
htm: o.toUpperCase(),
|
|
204
204
|
htu: i,
|
|
205
205
|
iat: Math.floor(Date.now() / 1e3)
|
|
206
206
|
};
|
|
207
207
|
if (t) {
|
|
208
|
-
const
|
|
209
|
-
u.ath =
|
|
208
|
+
const _ = new TextEncoder().encode(t), N = await crypto.subtle.digest("SHA-256", _);
|
|
209
|
+
u.ath = k(N);
|
|
210
210
|
}
|
|
211
|
-
const y =
|
|
211
|
+
const y = k(
|
|
212
212
|
new TextEncoder().encode(JSON.stringify(r)).buffer
|
|
213
|
-
), c =
|
|
213
|
+
), c = k(
|
|
214
214
|
new TextEncoder().encode(JSON.stringify(u)).buffer
|
|
215
|
-
), l = `${y}.${c}`,
|
|
215
|
+
), l = `${y}.${c}`, T = await crypto.subtle.sign(
|
|
216
216
|
{
|
|
217
217
|
name: "ECDSA",
|
|
218
218
|
hash: { name: "SHA-256" }
|
|
219
219
|
},
|
|
220
220
|
e,
|
|
221
221
|
new TextEncoder().encode(l)
|
|
222
|
-
),
|
|
223
|
-
return `${y}.${c}.${
|
|
222
|
+
), b = k(T);
|
|
223
|
+
return `${y}.${c}.${b}`;
|
|
224
224
|
} catch (e) {
|
|
225
225
|
return console.error("Failed to generate DPoP proof:", e), null;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
async function
|
|
229
|
-
return await
|
|
228
|
+
async function X() {
|
|
229
|
+
return await A() !== null;
|
|
230
230
|
}
|
|
231
|
-
const
|
|
232
|
-
|
|
231
|
+
const Q = R, B = {
|
|
232
|
+
isWebAuthnSupported: O,
|
|
233
|
+
isConditionalUISupported: j,
|
|
234
|
+
arrayBufferToBase64: h,
|
|
235
|
+
base64ToArrayBuffer: f,
|
|
236
|
+
arrayBufferToBase64url: k,
|
|
237
|
+
base64urlToArrayBuffer: W,
|
|
238
|
+
stringToArrayBuffer: S,
|
|
239
|
+
uint8ArrayToString: H,
|
|
240
|
+
getPasskeyEmail: G,
|
|
241
|
+
setPasskeyEmail: M,
|
|
242
|
+
clearPasskeyEmail: V,
|
|
243
|
+
toMinimalJWK: v,
|
|
244
|
+
calculateThumbprint: q,
|
|
245
|
+
getDPoPKey: A,
|
|
246
|
+
getDPoPPublicKeyJWK: C,
|
|
247
|
+
clearDPoPKey: $,
|
|
248
|
+
generateDPoPKeyPair: P,
|
|
249
|
+
generateDPoPProof: g,
|
|
250
|
+
isDPoPEnabled: X,
|
|
251
|
+
storeDPoPKey: Q
|
|
252
|
+
};
|
|
253
|
+
typeof window < "u" && (window.WebAuthn = B);
|
|
254
|
+
const Z = typeof window < "u" ? window : globalThis;
|
|
255
|
+
Z.WebAuthn = B;
|
|
256
|
+
const m = "postex-auth-token", w = "https://auth-stage.postexglobal.com/public/v1";
|
|
257
|
+
class ee extends Error {
|
|
233
258
|
constructor(n, t, e) {
|
|
234
259
|
super(e ?? `Request failed with status ${n}`), this.response = { status: n, data: t }, this.name = "AuthSDKFetchError";
|
|
235
260
|
}
|
|
236
261
|
}
|
|
237
|
-
const
|
|
238
|
-
class
|
|
262
|
+
const K = "auth_sdk_id_token", D = "auth_sdk_refresh_token";
|
|
263
|
+
class U {
|
|
239
264
|
constructor(n) {
|
|
240
265
|
this.config = n;
|
|
241
266
|
}
|
|
242
267
|
buildUrl(n, t) {
|
|
243
|
-
const e =
|
|
268
|
+
const e = w.replace(/\/$/, ""), s = n.startsWith("/") ? n : `/${n}`, r = `${e}${s}`;
|
|
244
269
|
if (!t || Object.keys(t).length === 0) return r;
|
|
245
|
-
const
|
|
246
|
-
return `${r}?${
|
|
270
|
+
const a = new URLSearchParams(t).toString();
|
|
271
|
+
return `${r}?${a}`;
|
|
247
272
|
}
|
|
248
273
|
async request(n, t, e) {
|
|
249
|
-
const
|
|
274
|
+
const s = this.buildUrl(t, e?.params), r = {
|
|
250
275
|
"Content-Type": "application/json",
|
|
251
276
|
Accept: "application/json",
|
|
252
277
|
"X-API-Key": this.config.apiKey ?? "",
|
|
253
278
|
...e?.headers
|
|
254
|
-
},
|
|
279
|
+
}, a = {
|
|
255
280
|
method: n,
|
|
256
281
|
credentials: "include",
|
|
257
282
|
headers: r
|
|
258
283
|
};
|
|
259
|
-
e?.body !== void 0 && e?.body !== null && (
|
|
260
|
-
const i = await fetch(
|
|
284
|
+
e?.body !== void 0 && e?.body !== null && (a.body = JSON.stringify(e.body));
|
|
285
|
+
const i = await fetch(s, a);
|
|
261
286
|
if (!i.ok) {
|
|
262
287
|
let c;
|
|
263
288
|
try {
|
|
@@ -266,7 +291,7 @@ class Q {
|
|
|
266
291
|
} catch {
|
|
267
292
|
c = void 0;
|
|
268
293
|
}
|
|
269
|
-
throw i.status === 401 && await this.clearTokens(), new
|
|
294
|
+
throw i.status === 401 && await this.clearTokens(), new ee(i.status, c);
|
|
270
295
|
}
|
|
271
296
|
const u = await i.text();
|
|
272
297
|
return { data: u ? JSON.parse(u) : {} };
|
|
@@ -280,14 +305,14 @@ class Q {
|
|
|
280
305
|
async getRequestAuthHeaders(n, t) {
|
|
281
306
|
const e = localStorage.getItem(m);
|
|
282
307
|
if (!e) return {};
|
|
283
|
-
const
|
|
308
|
+
const s = t.startsWith("http") ? t : `${w}${t}`, r = await g(
|
|
284
309
|
n.toUpperCase(),
|
|
285
|
-
|
|
310
|
+
s,
|
|
286
311
|
e
|
|
287
|
-
),
|
|
312
|
+
), a = {
|
|
288
313
|
Authorization: `Bearer ${e}`
|
|
289
314
|
};
|
|
290
|
-
return r && (
|
|
315
|
+
return r && (a.DPoP = r), a;
|
|
291
316
|
}
|
|
292
317
|
/**
|
|
293
318
|
* GET /auth/status - Check if client has trusted device session and what auth method is available.
|
|
@@ -319,22 +344,22 @@ class Q {
|
|
|
319
344
|
* Stores tokens from the response.
|
|
320
345
|
*/
|
|
321
346
|
async verifyOTP(n) {
|
|
322
|
-
await
|
|
323
|
-
const t = await
|
|
347
|
+
await P();
|
|
348
|
+
const t = await g(
|
|
324
349
|
"POST",
|
|
325
|
-
`${
|
|
350
|
+
`${w}/otp/verify`
|
|
326
351
|
), e = await this.request("POST", "/otp/verify", {
|
|
327
352
|
body: { otp: n },
|
|
328
353
|
headers: t ? { DPoP: t } : {}
|
|
329
|
-
}),
|
|
330
|
-
return
|
|
331
|
-
accessToken:
|
|
354
|
+
}), s = e.data.data ?? e.data, r = s.AuthenticationResult ?? s, a = r.access_token ?? r.accessToken ?? r.AccessToken, i = r.refresh_token ?? r.refreshToken ?? r.RefreshToken, u = r.id_token ?? r.idToken ?? r.IdToken, y = r.expires_in ?? r.expiresIn ?? r.ExpiresIn ?? 3600, c = r.token_type ?? r.tokenType ?? r.TokenType ?? "Bearer";
|
|
355
|
+
return a && await this.storeTokens({
|
|
356
|
+
accessToken: a,
|
|
332
357
|
refreshToken: i ?? "",
|
|
333
358
|
idToken: u ?? "",
|
|
334
359
|
expiresIn: y ?? 3600,
|
|
335
360
|
tokenType: c ?? "Bearer"
|
|
336
361
|
}), {
|
|
337
|
-
access_token:
|
|
362
|
+
access_token: a,
|
|
338
363
|
refresh_token: i ?? "",
|
|
339
364
|
id_token: u ?? "",
|
|
340
365
|
expires_in: y,
|
|
@@ -365,17 +390,17 @@ class Q {
|
|
|
365
390
|
{
|
|
366
391
|
body: {}
|
|
367
392
|
}
|
|
368
|
-
), t = n.data.data ?? n.data, e = t.AuthenticationResult ?? t,
|
|
369
|
-
return
|
|
370
|
-
accessToken:
|
|
393
|
+
), t = n.data.data ?? n.data, e = t.AuthenticationResult ?? t, s = e.access_token ?? e.accessToken ?? e.AccessToken, r = e.refresh_token ?? e.refreshToken ?? e.RefreshToken, a = e.id_token ?? e.idToken ?? e.IdToken, i = e.expires_in ?? e.expiresIn ?? e.ExpiresIn ?? 3600, u = e.token_type ?? e.tokenType ?? e.TokenType ?? "Bearer";
|
|
394
|
+
return s && await this.storeTokens({
|
|
395
|
+
accessToken: s,
|
|
371
396
|
refreshToken: r ?? "",
|
|
372
|
-
idToken:
|
|
397
|
+
idToken: a ?? "",
|
|
373
398
|
expiresIn: i ?? 3600,
|
|
374
399
|
tokenType: u ?? "Bearer"
|
|
375
400
|
}), {
|
|
376
|
-
access_token:
|
|
401
|
+
access_token: s,
|
|
377
402
|
refresh_token: r ?? "",
|
|
378
|
-
id_token:
|
|
403
|
+
id_token: a ?? "",
|
|
379
404
|
expires_in: i,
|
|
380
405
|
token_type: u,
|
|
381
406
|
verified: e.verified ?? e.Verified ?? !0,
|
|
@@ -398,13 +423,13 @@ class Q {
|
|
|
398
423
|
let e;
|
|
399
424
|
if (t?.user?.id)
|
|
400
425
|
try {
|
|
401
|
-
e =
|
|
426
|
+
e = f(t.user.id);
|
|
402
427
|
} catch {
|
|
403
|
-
e =
|
|
428
|
+
e = S(t.user.id);
|
|
404
429
|
}
|
|
405
430
|
else
|
|
406
|
-
e =
|
|
407
|
-
const
|
|
431
|
+
e = S(n);
|
|
432
|
+
const s = (t.pubKeyCredParams ?? [
|
|
408
433
|
{ type: "public-key", alg: -7 },
|
|
409
434
|
{ type: "public-key", alg: -257 }
|
|
410
435
|
]).map((l) => ({
|
|
@@ -413,11 +438,11 @@ class Q {
|
|
|
413
438
|
}));
|
|
414
439
|
t.excludeCredentials?.map((l) => ({
|
|
415
440
|
type: "public-key",
|
|
416
|
-
id:
|
|
441
|
+
id: f(l.id),
|
|
417
442
|
transports: l.transports
|
|
418
443
|
}));
|
|
419
444
|
const r = {
|
|
420
|
-
challenge:
|
|
445
|
+
challenge: f(t.challenge),
|
|
421
446
|
rp: {
|
|
422
447
|
name: t.rp?.name ?? "XPay",
|
|
423
448
|
id: t.rp?.id ?? window.location.hostname
|
|
@@ -427,27 +452,27 @@ class Q {
|
|
|
427
452
|
name: t.user?.name ?? n,
|
|
428
453
|
displayName: t.user?.displayName ?? n
|
|
429
454
|
},
|
|
430
|
-
pubKeyCredParams:
|
|
455
|
+
pubKeyCredParams: s,
|
|
431
456
|
timeout: t.timeout ?? 6e4,
|
|
432
457
|
attestation: t.attestation ?? "none",
|
|
433
458
|
authenticatorSelection: t.authenticatorSelection ?? {
|
|
434
459
|
residentKey: "required",
|
|
435
460
|
userVerification: "required"
|
|
436
461
|
}
|
|
437
|
-
},
|
|
462
|
+
}, a = await navigator.credentials.create({
|
|
438
463
|
publicKey: r
|
|
439
464
|
});
|
|
440
|
-
if (!
|
|
441
|
-
const i =
|
|
465
|
+
if (!a) throw new Error("Credential creation failed");
|
|
466
|
+
const i = a.response, u = {
|
|
442
467
|
clientDataJSON: h(i.clientDataJSON),
|
|
443
468
|
attestationObject: h(i.attestationObject),
|
|
444
|
-
rawId: h(
|
|
469
|
+
rawId: h(a.rawId)
|
|
445
470
|
};
|
|
446
471
|
if (!u.rawId) throw new Error("Raw ID is required");
|
|
447
|
-
await
|
|
448
|
-
const y = await
|
|
472
|
+
await P();
|
|
473
|
+
const y = await g(
|
|
449
474
|
"POST",
|
|
450
|
-
`${
|
|
475
|
+
`${w}/webauthn/register/challenge`
|
|
451
476
|
), c = await this.request(
|
|
452
477
|
"POST",
|
|
453
478
|
"/webauthn/register/challenge",
|
|
@@ -466,13 +491,13 @@ class Q {
|
|
|
466
491
|
rp: t,
|
|
467
492
|
credentialIds: e
|
|
468
493
|
}) {
|
|
469
|
-
const
|
|
494
|
+
const s = await navigator.credentials.get({
|
|
470
495
|
publicKey: {
|
|
471
|
-
challenge:
|
|
496
|
+
challenge: f(n),
|
|
472
497
|
rpId: t?.host ?? void 0,
|
|
473
|
-
allowCredentials: e.map((
|
|
498
|
+
allowCredentials: e.map((_) => ({
|
|
474
499
|
type: "public-key",
|
|
475
|
-
id:
|
|
500
|
+
id: f(_)
|
|
476
501
|
// Hint browser about possible transports for faster authenticator discovery
|
|
477
502
|
// transports: ["internal", "hybrid"] as AuthenticatorTransport[],
|
|
478
503
|
})),
|
|
@@ -480,38 +505,38 @@ class Q {
|
|
|
480
505
|
userVerification: "required"
|
|
481
506
|
}
|
|
482
507
|
});
|
|
483
|
-
if (!
|
|
484
|
-
const r =
|
|
508
|
+
if (!s) throw new Error("Authentication failed");
|
|
509
|
+
const r = s.response, a = {
|
|
485
510
|
clientDataJSON: h(r.clientDataJSON),
|
|
486
511
|
authenticatorData: h(
|
|
487
512
|
r.authenticatorData
|
|
488
513
|
),
|
|
489
514
|
signature: h(r.signature),
|
|
490
|
-
rawId: h(
|
|
515
|
+
rawId: h(s.rawId),
|
|
491
516
|
userHandle: r.userHandle ? h(r.userHandle) : ""
|
|
492
517
|
};
|
|
493
|
-
await
|
|
494
|
-
const i = await
|
|
518
|
+
await P();
|
|
519
|
+
const i = await g(
|
|
495
520
|
"POST",
|
|
496
|
-
`${
|
|
521
|
+
`${w}/webauthn/authenticate/challenge`
|
|
497
522
|
), u = await this.request(
|
|
498
523
|
"POST",
|
|
499
524
|
"/webauthn/authenticate/challenge",
|
|
500
525
|
{
|
|
501
|
-
body:
|
|
526
|
+
body: a,
|
|
502
527
|
headers: i ? { DPoP: i } : {}
|
|
503
528
|
}
|
|
504
|
-
), y = u.data.data ?? u.data, c = y.AuthenticationResult ?? y, l = c.AccessToken ?? c.accessToken ?? c.access_token,
|
|
529
|
+
), y = u.data.data ?? u.data, c = y.AuthenticationResult ?? y, l = c.AccessToken ?? c.accessToken ?? c.access_token, T = c.RefreshToken ?? c.refreshToken ?? c.refresh_token, b = c.IdToken ?? c.idToken ?? c.id_token;
|
|
505
530
|
return l && await this.storeTokens({
|
|
506
531
|
accessToken: l,
|
|
507
|
-
refreshToken:
|
|
508
|
-
idToken:
|
|
532
|
+
refreshToken: T ?? "",
|
|
533
|
+
idToken: b ?? "",
|
|
509
534
|
expiresIn: c.expiresIn ?? c.ExpiresIn ?? 3600,
|
|
510
535
|
tokenType: c.tokenType ?? c.token_type ?? "Bearer"
|
|
511
536
|
}), {
|
|
512
537
|
access_token: l,
|
|
513
|
-
refresh_token:
|
|
514
|
-
id_token:
|
|
538
|
+
refresh_token: T ?? "",
|
|
539
|
+
id_token: b,
|
|
515
540
|
email: c.email,
|
|
516
541
|
name: c.name ?? c.userName,
|
|
517
542
|
expiresIn: c.expiresIn ?? c.ExpiresIn,
|
|
@@ -523,35 +548,35 @@ class Q {
|
|
|
523
548
|
* GET /webauthn/credentials/:username - Get user's passkey status.
|
|
524
549
|
*/
|
|
525
550
|
async getPasskeyStatus(n) {
|
|
526
|
-
const e = `/webauthn/credentials/${encodeURIComponent(n)}`,
|
|
527
|
-
headers:
|
|
528
|
-
}),
|
|
551
|
+
const e = `/webauthn/credentials/${encodeURIComponent(n)}`, s = await this.signRequest("GET", e), r = await this.request("GET", e, {
|
|
552
|
+
headers: s.headers
|
|
553
|
+
}), a = r.data.data ?? r.data;
|
|
529
554
|
return {
|
|
530
|
-
...
|
|
531
|
-
hasCredentials: !!(
|
|
555
|
+
...a,
|
|
556
|
+
hasCredentials: !!(a.hasCredentials ?? a.credentialId)
|
|
532
557
|
};
|
|
533
558
|
}
|
|
534
559
|
/**
|
|
535
560
|
* DELETE /webauthn/credentials/:username - Remove passkey.
|
|
536
561
|
*/
|
|
537
562
|
async removePasskey(n) {
|
|
538
|
-
const e = `/webauthn/credentials/${encodeURIComponent(n)}`,
|
|
563
|
+
const e = `/webauthn/credentials/${encodeURIComponent(n)}`, s = await this.signRequest("DELETE", e);
|
|
539
564
|
await this.request("DELETE", e, {
|
|
540
|
-
headers:
|
|
565
|
+
headers: s.headers
|
|
541
566
|
});
|
|
542
567
|
}
|
|
543
568
|
/**
|
|
544
569
|
* Signs a request with DPoP and Authorization headers (internal use).
|
|
545
570
|
*/
|
|
546
571
|
async signRequest(n, t, e = {}) {
|
|
547
|
-
const
|
|
572
|
+
const s = t.startsWith("http") ? t : `${w}${t}`, r = await this.getRequestAuthHeaders(n, s);
|
|
548
573
|
return { ...e, headers: { ...e.headers, ...r } };
|
|
549
574
|
}
|
|
550
575
|
/**
|
|
551
576
|
* Replaces native fetch or Axios with a DPoP-signed version.
|
|
552
577
|
*/
|
|
553
578
|
async authenticatedFetch(n, t) {
|
|
554
|
-
const e = typeof n == "string" ? n : n instanceof URL ? n.toString() : n.url,
|
|
579
|
+
const e = typeof n == "string" ? n : n instanceof URL ? n.toString() : n.url, s = t?.method || "GET", r = await this.signRequest(s, e, {
|
|
555
580
|
headers: t?.headers
|
|
556
581
|
});
|
|
557
582
|
return fetch(n, { ...t, headers: r.headers });
|
|
@@ -560,13 +585,13 @@ class Q {
|
|
|
560
585
|
* Store tokens from /webauthn/authenticate (per spec: sessionStorage preferred).
|
|
561
586
|
*/
|
|
562
587
|
async storeTokens(n) {
|
|
563
|
-
localStorage.setItem(m, n.accessToken), n.refreshToken && localStorage.setItem(
|
|
588
|
+
localStorage.setItem(m, n.accessToken), n.refreshToken && localStorage.setItem(D, n.refreshToken), n.idToken && localStorage.setItem(K, n.idToken);
|
|
564
589
|
}
|
|
565
590
|
/**
|
|
566
591
|
* Clear stored tokens (call on logout).
|
|
567
592
|
*/
|
|
568
593
|
async clearTokens() {
|
|
569
|
-
localStorage.removeItem(m), localStorage.removeItem(
|
|
594
|
+
localStorage.removeItem(m), localStorage.removeItem(K), localStorage.removeItem(D);
|
|
570
595
|
}
|
|
571
596
|
/**
|
|
572
597
|
* POST /auth/refresh - Refresh access token using server-stored refresh token.
|
|
@@ -576,17 +601,17 @@ class Q {
|
|
|
576
601
|
async refreshToken() {
|
|
577
602
|
const n = await this.request("POST", "/auth/refresh", {
|
|
578
603
|
body: {}
|
|
579
|
-
}), t = n.data.data ?? n.data, e = t.access_token,
|
|
604
|
+
}), t = n.data.data ?? n.data, e = t.access_token, s = t.id_token ?? "", r = t.token_type ?? "Bearer", a = t.expires_in ?? 3600;
|
|
580
605
|
return e && await this.storeTokens({
|
|
581
606
|
accessToken: e,
|
|
582
|
-
idToken:
|
|
583
|
-
expiresIn:
|
|
607
|
+
idToken: s,
|
|
608
|
+
expiresIn: a,
|
|
584
609
|
tokenType: r
|
|
585
610
|
}), {
|
|
586
611
|
access_token: e,
|
|
587
|
-
id_token:
|
|
612
|
+
id_token: s,
|
|
588
613
|
token_type: r,
|
|
589
|
-
expires_in:
|
|
614
|
+
expires_in: a
|
|
590
615
|
};
|
|
591
616
|
}
|
|
592
617
|
/**
|
|
@@ -596,7 +621,7 @@ class Q {
|
|
|
596
621
|
async logout() {
|
|
597
622
|
try {
|
|
598
623
|
const n = await this.getAccessToken(), t = {};
|
|
599
|
-
n && (t.Authorization = `Bearer ${n}`), await this.request("POST", "/auth/logout", { body: {}, headers: t }),
|
|
624
|
+
n && (t.Authorization = `Bearer ${n}`), await this.request("POST", "/auth/logout", { body: {}, headers: t }), $();
|
|
600
625
|
} catch {
|
|
601
626
|
}
|
|
602
627
|
await this.clearTokens();
|
|
@@ -605,28 +630,31 @@ class Q {
|
|
|
605
630
|
return localStorage.getItem(m);
|
|
606
631
|
}
|
|
607
632
|
}
|
|
633
|
+
typeof window < "u" && (window.AuthSDK = U);
|
|
634
|
+
const te = typeof window < "u" ? window : globalThis;
|
|
635
|
+
te.AuthSDK = U;
|
|
608
636
|
export {
|
|
609
|
-
|
|
610
|
-
|
|
637
|
+
U as AuthSDK,
|
|
638
|
+
ee as AuthSDKFetchError,
|
|
611
639
|
h as arrayBufferToBase64,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
640
|
+
k as arrayBufferToBase64url,
|
|
641
|
+
f as base64ToArrayBuffer,
|
|
642
|
+
W as base64urlToArrayBuffer,
|
|
643
|
+
q as calculateThumbprint,
|
|
644
|
+
$ as clearDPoPKey,
|
|
617
645
|
V as clearPasskeyEmail,
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
646
|
+
P as generateDPoPKeyPair,
|
|
647
|
+
g as generateDPoPProof,
|
|
648
|
+
A as getDPoPKey,
|
|
649
|
+
C as getDPoPPublicKeyJWK,
|
|
622
650
|
G as getPasskeyEmail,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
651
|
+
j as isConditionalUISupported,
|
|
652
|
+
X as isDPoPEnabled,
|
|
653
|
+
O as isWebAuthnSupported,
|
|
626
654
|
M as setPasskeyEmail,
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
655
|
+
Q as storeDPoPKey,
|
|
656
|
+
S as stringToArrayBuffer,
|
|
657
|
+
v as toMinimalJWK,
|
|
658
|
+
H as uint8ArrayToString
|
|
631
659
|
};
|
|
632
660
|
//# sourceMappingURL=postex-auth-sdk-stage.es.js.map
|