@iqauth/sdk 2.3.0 → 2.5.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 +110 -0
- package/dist/browser-session.d.mts +3 -2
- package/dist/browser-session.d.ts +3 -2
- package/dist/browser.d.mts +64 -29
- package/dist/browser.d.ts +64 -29
- package/dist/browser.js +782 -38
- package/dist/browser.mjs +43 -3
- package/dist/bundle-LUKDQYVQ.mjs +374 -0
- package/dist/chunk-3JULWS6F.mjs +106 -0
- package/dist/chunk-5T7GHBX6.mjs +1165 -0
- package/dist/{chunk-KGEPDXHU.mjs → chunk-6TDJJER7.mjs} +2 -2
- package/dist/{chunk-RACIPVLD.mjs → chunk-76W5TLQQ.mjs} +262 -220
- package/dist/{chunk-EKTNEZIH.mjs → chunk-BVV54LPI.mjs} +37 -5
- package/dist/chunk-LIZYFXH7.mjs +90 -0
- package/dist/chunk-MKKZULZR.mjs +241 -0
- package/dist/chunk-SL3KRS4W.mjs +54 -0
- package/dist/chunk-TKZTCPEK.mjs +232 -0
- package/dist/chunk-UKZLOHZG.mjs +83 -0
- package/dist/cli/index.js +144 -36
- package/dist/cli/index.mjs +1 -1
- package/dist/{client-DTX4hNdS.d.ts → client-BNQe3AgF.d.ts} +3 -62
- package/dist/{client-vdh2a9fJ.d.mts → client-kYlJFgPv.d.mts} +3 -62
- package/dist/doctor-YYNHNMLD.mjs +198 -0
- package/dist/{express-A0-dWEMy.d.mts → express-B6_1vBYZ.d.mts} +23 -2
- package/dist/{express-Bo_pJKHN.d.ts → express-CHpfa7D_.d.ts} +23 -2
- package/dist/express.d.mts +5 -4
- package/dist/express.d.ts +5 -4
- package/dist/express.js +36 -4
- package/dist/express.mjs +8 -8
- package/dist/fastify.js +2 -2
- package/dist/fastify.mjs +4 -4
- package/dist/hono.js +2 -2
- package/dist/hono.mjs +4 -4
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +500 -4
- package/dist/index.mjs +29 -9
- package/dist/locales.d.mts +53 -0
- package/dist/locales.d.ts +53 -0
- package/dist/locales.js +1202 -0
- package/dist/locales.mjs +29 -0
- package/dist/mobile.d.mts +3 -2
- package/dist/mobile.d.ts +3 -2
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/next.mjs +1 -1
- package/dist/provisioningBridge-88xjOS2n.d.mts +86 -0
- package/dist/provisioningBridge-DnTfzdZK.d.ts +86 -0
- package/dist/react.d.mts +1349 -10
- package/dist/react.d.ts +1349 -10
- package/dist/react.js +2985 -567
- package/dist/react.mjs +1517 -94
- package/dist/reverify-4UEJXUS6.mjs +16 -0
- package/dist/server/handlers.d.mts +10 -1
- package/dist/server/handlers.d.ts +10 -1
- package/dist/server/handlers.js +2 -2
- package/dist/server/handlers.mjs +1 -1
- package/dist/server.d.mts +5 -3
- package/dist/server.d.ts +5 -3
- package/dist/server.js +89 -4
- package/dist/server.mjs +12 -8
- package/dist/service.d.mts +3 -2
- package/dist/service.d.ts +3 -2
- package/dist/signIn-CCY4JE5G.mjs +15 -0
- package/dist/{signIn-Cd0P4y9d.d.mts → signIn-CiIBTJIh.d.mts} +224 -4
- package/dist/{signIn-DKakyzeu.d.ts → signIn-OCr88Zf8.d.ts} +224 -4
- package/dist/test.d.mts +86 -0
- package/dist/test.d.ts +86 -0
- package/dist/test.js +289 -0
- package/dist/test.mjs +9 -0
- package/dist/tokens-DCyzzn8L.d.mts +63 -0
- package/dist/tokens-aHiGFr_E.d.ts +63 -0
- package/dist/types-6bNdxesb.d.mts +196 -0
- package/dist/types-6bNdxesb.d.ts +196 -0
- package/dist/{types-Cxl3bQHt.d.mts → types-DZAflmmq.d.mts} +6 -0
- package/dist/{types-Cxl3bQHt.d.ts → types-DZAflmmq.d.ts} +6 -0
- package/dist/webhooks.d.mts +61 -0
- package/dist/webhooks.d.ts +61 -0
- package/dist/webhooks.js +119 -0
- package/dist/webhooks.mjs +11 -0
- package/dist/ws.d.mts +73 -0
- package/dist/ws.d.ts +73 -0
- package/dist/ws.js +397 -0
- package/dist/ws.mjs +12 -0
- package/package.json +22 -2
- package/dist/doctor-A5E7LSFW.mjs +0 -90
package/dist/browser.mjs
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
PRIOR_SESSION_STORAGE_KEY,
|
|
3
|
+
enterImpersonation,
|
|
4
|
+
exitImpersonation,
|
|
5
|
+
reverify,
|
|
6
|
+
withReverification
|
|
7
|
+
} from "./chunk-LIZYFXH7.mjs";
|
|
8
|
+
import {
|
|
9
|
+
AccountRegistry,
|
|
10
|
+
MultiAccountTokenStore,
|
|
3
11
|
SessionManager,
|
|
12
|
+
beginPasskeyAuthentication,
|
|
13
|
+
beginPasskeyRegistration,
|
|
14
|
+
enrollPasskey,
|
|
15
|
+
finishPasskeyAuthentication,
|
|
16
|
+
finishPasskeyRegistration,
|
|
17
|
+
linkProvider,
|
|
18
|
+
listLinkedIdentities,
|
|
19
|
+
requestMagicLink,
|
|
20
|
+
signInWithPasskey,
|
|
21
|
+
unlinkProvider,
|
|
22
|
+
verifyMagicLink
|
|
23
|
+
} from "./chunk-76W5TLQQ.mjs";
|
|
24
|
+
import {
|
|
25
|
+
REFRESH_COOKIE,
|
|
4
26
|
buildSignInUrl,
|
|
5
27
|
clearCookie,
|
|
6
28
|
createPkcePair,
|
|
@@ -12,7 +34,7 @@ import {
|
|
|
12
34
|
setCookie,
|
|
13
35
|
signIn,
|
|
14
36
|
signOut
|
|
15
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-TKZTCPEK.mjs";
|
|
16
38
|
import {
|
|
17
39
|
encodePublishableKey,
|
|
18
40
|
isPublishableKey,
|
|
@@ -25,23 +47,41 @@ import {
|
|
|
25
47
|
} from "./chunk-6I6RM4MN.mjs";
|
|
26
48
|
import "./chunk-Y6FXYEAI.mjs";
|
|
27
49
|
export {
|
|
50
|
+
AccountRegistry,
|
|
28
51
|
ErrorCodes,
|
|
29
52
|
IQAuthError,
|
|
53
|
+
MultiAccountTokenStore,
|
|
54
|
+
PRIOR_SESSION_STORAGE_KEY,
|
|
30
55
|
REFRESH_COOKIE,
|
|
31
56
|
SessionManager,
|
|
57
|
+
beginPasskeyAuthentication,
|
|
58
|
+
beginPasskeyRegistration,
|
|
32
59
|
buildSignInUrl,
|
|
33
60
|
clearCookie,
|
|
34
61
|
createPkcePair,
|
|
35
62
|
encodePublishableKey,
|
|
63
|
+
enrollPasskey,
|
|
64
|
+
enterImpersonation,
|
|
65
|
+
exitImpersonation,
|
|
66
|
+
finishPasskeyAuthentication,
|
|
67
|
+
finishPasskeyRegistration,
|
|
36
68
|
getCookie,
|
|
37
69
|
handleAuthCallback,
|
|
38
70
|
isPublishableKey,
|
|
39
71
|
isSecretKey,
|
|
72
|
+
linkProvider,
|
|
73
|
+
listLinkedIdentities,
|
|
40
74
|
parsePublishableKey,
|
|
41
75
|
randomUrlSafe,
|
|
42
76
|
redirectToSignIn,
|
|
77
|
+
requestMagicLink,
|
|
78
|
+
reverify,
|
|
43
79
|
s256Challenge,
|
|
44
80
|
setCookie,
|
|
45
81
|
signIn,
|
|
46
|
-
|
|
82
|
+
signInWithPasskey,
|
|
83
|
+
signOut,
|
|
84
|
+
unlinkProvider,
|
|
85
|
+
verifyMagicLink,
|
|
86
|
+
withReverification
|
|
47
87
|
};
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import "./chunk-Y6FXYEAI.mjs";
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/@simplewebauthn/browser/dist/bundle/index.js
|
|
4
|
+
function bufferToBase64URLString(buffer) {
|
|
5
|
+
const bytes = new Uint8Array(buffer);
|
|
6
|
+
let str = "";
|
|
7
|
+
for (const charCode of bytes) {
|
|
8
|
+
str += String.fromCharCode(charCode);
|
|
9
|
+
}
|
|
10
|
+
const base64String = btoa(str);
|
|
11
|
+
return base64String.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
12
|
+
}
|
|
13
|
+
function base64URLStringToBuffer(base64URLString) {
|
|
14
|
+
const base64 = base64URLString.replace(/-/g, "+").replace(/_/g, "/");
|
|
15
|
+
const padLength = (4 - base64.length % 4) % 4;
|
|
16
|
+
const padded = base64.padEnd(base64.length + padLength, "=");
|
|
17
|
+
const binary = atob(padded);
|
|
18
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
19
|
+
const bytes = new Uint8Array(buffer);
|
|
20
|
+
for (let i = 0; i < binary.length; i++) {
|
|
21
|
+
bytes[i] = binary.charCodeAt(i);
|
|
22
|
+
}
|
|
23
|
+
return buffer;
|
|
24
|
+
}
|
|
25
|
+
function browserSupportsWebAuthn() {
|
|
26
|
+
return window?.PublicKeyCredential !== void 0 && typeof window.PublicKeyCredential === "function";
|
|
27
|
+
}
|
|
28
|
+
function toPublicKeyCredentialDescriptor(descriptor) {
|
|
29
|
+
const { id } = descriptor;
|
|
30
|
+
return {
|
|
31
|
+
...descriptor,
|
|
32
|
+
id: base64URLStringToBuffer(id),
|
|
33
|
+
transports: descriptor.transports
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function isValidDomain(hostname) {
|
|
37
|
+
return hostname === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname);
|
|
38
|
+
}
|
|
39
|
+
var WebAuthnError = class extends Error {
|
|
40
|
+
constructor({ message, code, cause, name }) {
|
|
41
|
+
super(message, { cause });
|
|
42
|
+
this.name = name ?? cause.name;
|
|
43
|
+
this.code = code;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function identifyRegistrationError({ error, options }) {
|
|
47
|
+
const { publicKey } = options;
|
|
48
|
+
if (!publicKey) {
|
|
49
|
+
throw Error("options was missing required publicKey property");
|
|
50
|
+
}
|
|
51
|
+
if (error.name === "AbortError") {
|
|
52
|
+
if (options.signal instanceof AbortSignal) {
|
|
53
|
+
return new WebAuthnError({
|
|
54
|
+
message: "Registration ceremony was sent an abort signal",
|
|
55
|
+
code: "ERROR_CEREMONY_ABORTED",
|
|
56
|
+
cause: error
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} else if (error.name === "ConstraintError") {
|
|
60
|
+
if (publicKey.authenticatorSelection?.requireResidentKey === true) {
|
|
61
|
+
return new WebAuthnError({
|
|
62
|
+
message: "Discoverable credentials were required but no available authenticator supported it",
|
|
63
|
+
code: "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT",
|
|
64
|
+
cause: error
|
|
65
|
+
});
|
|
66
|
+
} else if (options.mediation === "conditional" && publicKey.authenticatorSelection?.userVerification === "required") {
|
|
67
|
+
return new WebAuthnError({
|
|
68
|
+
message: "User verification was required during automatic registration but it could not be performed",
|
|
69
|
+
code: "ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE",
|
|
70
|
+
cause: error
|
|
71
|
+
});
|
|
72
|
+
} else if (publicKey.authenticatorSelection?.userVerification === "required") {
|
|
73
|
+
return new WebAuthnError({
|
|
74
|
+
message: "User verification was required but no available authenticator supported it",
|
|
75
|
+
code: "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT",
|
|
76
|
+
cause: error
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
} else if (error.name === "InvalidStateError") {
|
|
80
|
+
return new WebAuthnError({
|
|
81
|
+
message: "The authenticator was previously registered",
|
|
82
|
+
code: "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED",
|
|
83
|
+
cause: error
|
|
84
|
+
});
|
|
85
|
+
} else if (error.name === "NotAllowedError") {
|
|
86
|
+
return new WebAuthnError({
|
|
87
|
+
message: error.message,
|
|
88
|
+
code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
|
|
89
|
+
cause: error
|
|
90
|
+
});
|
|
91
|
+
} else if (error.name === "NotSupportedError") {
|
|
92
|
+
const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === "public-key");
|
|
93
|
+
if (validPubKeyCredParams.length === 0) {
|
|
94
|
+
return new WebAuthnError({
|
|
95
|
+
message: 'No entry in pubKeyCredParams was of type "public-key"',
|
|
96
|
+
code: "ERROR_MALFORMED_PUBKEYCREDPARAMS",
|
|
97
|
+
cause: error
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return new WebAuthnError({
|
|
101
|
+
message: "No available authenticator supported any of the specified pubKeyCredParams algorithms",
|
|
102
|
+
code: "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG",
|
|
103
|
+
cause: error
|
|
104
|
+
});
|
|
105
|
+
} else if (error.name === "SecurityError") {
|
|
106
|
+
const effectiveDomain = window.location.hostname;
|
|
107
|
+
if (!isValidDomain(effectiveDomain)) {
|
|
108
|
+
return new WebAuthnError({
|
|
109
|
+
message: `${window.location.hostname} is an invalid domain`,
|
|
110
|
+
code: "ERROR_INVALID_DOMAIN",
|
|
111
|
+
cause: error
|
|
112
|
+
});
|
|
113
|
+
} else if (publicKey.rp.id !== effectiveDomain) {
|
|
114
|
+
return new WebAuthnError({
|
|
115
|
+
message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
|
|
116
|
+
code: "ERROR_INVALID_RP_ID",
|
|
117
|
+
cause: error
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
} else if (error.name === "TypeError") {
|
|
121
|
+
if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
|
|
122
|
+
return new WebAuthnError({
|
|
123
|
+
message: "User ID was not between 1 and 64 characters",
|
|
124
|
+
code: "ERROR_INVALID_USER_ID_LENGTH",
|
|
125
|
+
cause: error
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
} else if (error.name === "UnknownError") {
|
|
129
|
+
return new WebAuthnError({
|
|
130
|
+
message: "The authenticator was unable to process the specified options, or could not create a new credential",
|
|
131
|
+
code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
|
|
132
|
+
cause: error
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return error;
|
|
136
|
+
}
|
|
137
|
+
var BaseWebAuthnAbortService = class {
|
|
138
|
+
createNewAbortSignal() {
|
|
139
|
+
if (this.controller) {
|
|
140
|
+
const abortError = new Error("Cancelling existing WebAuthn API call for new one");
|
|
141
|
+
abortError.name = "AbortError";
|
|
142
|
+
this.controller.abort(abortError);
|
|
143
|
+
}
|
|
144
|
+
const newController = new AbortController();
|
|
145
|
+
this.controller = newController;
|
|
146
|
+
return newController.signal;
|
|
147
|
+
}
|
|
148
|
+
cancelCeremony() {
|
|
149
|
+
if (this.controller) {
|
|
150
|
+
const abortError = new Error("Manually cancelling existing WebAuthn API call");
|
|
151
|
+
abortError.name = "AbortError";
|
|
152
|
+
this.controller.abort(abortError);
|
|
153
|
+
this.controller = void 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var WebAuthnAbortService = new BaseWebAuthnAbortService();
|
|
158
|
+
var attachments = ["cross-platform", "platform"];
|
|
159
|
+
function toAuthenticatorAttachment(attachment) {
|
|
160
|
+
if (!attachment) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (attachments.indexOf(attachment) < 0) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
return attachment;
|
|
167
|
+
}
|
|
168
|
+
async function startRegistration(options) {
|
|
169
|
+
const { optionsJSON, useAutoRegister = false } = options;
|
|
170
|
+
if (!browserSupportsWebAuthn()) {
|
|
171
|
+
throw new Error("WebAuthn is not supported in this browser");
|
|
172
|
+
}
|
|
173
|
+
const publicKey = {
|
|
174
|
+
...optionsJSON,
|
|
175
|
+
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
176
|
+
user: {
|
|
177
|
+
...optionsJSON.user,
|
|
178
|
+
id: base64URLStringToBuffer(optionsJSON.user.id)
|
|
179
|
+
},
|
|
180
|
+
excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor)
|
|
181
|
+
};
|
|
182
|
+
const createOptions = {};
|
|
183
|
+
if (useAutoRegister) {
|
|
184
|
+
createOptions.mediation = "conditional";
|
|
185
|
+
}
|
|
186
|
+
createOptions.publicKey = publicKey;
|
|
187
|
+
createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
188
|
+
let credential;
|
|
189
|
+
try {
|
|
190
|
+
credential = await navigator.credentials.create(createOptions);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
throw identifyRegistrationError({ error: err, options: createOptions });
|
|
193
|
+
}
|
|
194
|
+
if (!credential) {
|
|
195
|
+
throw new Error("Registration was not completed");
|
|
196
|
+
}
|
|
197
|
+
const { id, rawId, response, type } = credential;
|
|
198
|
+
let transports = void 0;
|
|
199
|
+
if (typeof response.getTransports === "function") {
|
|
200
|
+
transports = response.getTransports();
|
|
201
|
+
}
|
|
202
|
+
let responsePublicKeyAlgorithm = void 0;
|
|
203
|
+
if (typeof response.getPublicKeyAlgorithm === "function") {
|
|
204
|
+
try {
|
|
205
|
+
responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
|
|
206
|
+
} catch (error) {
|
|
207
|
+
warnOnBrokenImplementation("getPublicKeyAlgorithm()", error);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let responsePublicKey = void 0;
|
|
211
|
+
if (typeof response.getPublicKey === "function") {
|
|
212
|
+
try {
|
|
213
|
+
const _publicKey = response.getPublicKey();
|
|
214
|
+
if (_publicKey !== null) {
|
|
215
|
+
responsePublicKey = bufferToBase64URLString(_publicKey);
|
|
216
|
+
}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
warnOnBrokenImplementation("getPublicKey()", error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
let responseAuthenticatorData;
|
|
222
|
+
if (typeof response.getAuthenticatorData === "function") {
|
|
223
|
+
try {
|
|
224
|
+
responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
|
|
225
|
+
} catch (error) {
|
|
226
|
+
warnOnBrokenImplementation("getAuthenticatorData()", error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
id,
|
|
231
|
+
rawId: bufferToBase64URLString(rawId),
|
|
232
|
+
response: {
|
|
233
|
+
attestationObject: bufferToBase64URLString(response.attestationObject),
|
|
234
|
+
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
235
|
+
transports,
|
|
236
|
+
publicKeyAlgorithm: responsePublicKeyAlgorithm,
|
|
237
|
+
publicKey: responsePublicKey,
|
|
238
|
+
authenticatorData: responseAuthenticatorData
|
|
239
|
+
},
|
|
240
|
+
type,
|
|
241
|
+
clientExtensionResults: credential.getClientExtensionResults(),
|
|
242
|
+
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function warnOnBrokenImplementation(methodName, cause) {
|
|
246
|
+
console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.
|
|
247
|
+
`, cause);
|
|
248
|
+
}
|
|
249
|
+
function browserSupportsWebAuthnAutofill() {
|
|
250
|
+
if (!browserSupportsWebAuthn()) {
|
|
251
|
+
return new Promise((resolve) => resolve(false));
|
|
252
|
+
}
|
|
253
|
+
const globalPublicKeyCredential = window.PublicKeyCredential;
|
|
254
|
+
if (globalPublicKeyCredential.isConditionalMediationAvailable === void 0) {
|
|
255
|
+
return new Promise((resolve) => resolve(false));
|
|
256
|
+
}
|
|
257
|
+
return globalPublicKeyCredential.isConditionalMediationAvailable();
|
|
258
|
+
}
|
|
259
|
+
function identifyAuthenticationError({ error, options }) {
|
|
260
|
+
const { publicKey } = options;
|
|
261
|
+
if (!publicKey) {
|
|
262
|
+
throw Error("options was missing required publicKey property");
|
|
263
|
+
}
|
|
264
|
+
if (error.name === "AbortError") {
|
|
265
|
+
if (options.signal instanceof AbortSignal) {
|
|
266
|
+
return new WebAuthnError({
|
|
267
|
+
message: "Authentication ceremony was sent an abort signal",
|
|
268
|
+
code: "ERROR_CEREMONY_ABORTED",
|
|
269
|
+
cause: error
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
} else if (error.name === "NotAllowedError") {
|
|
273
|
+
return new WebAuthnError({
|
|
274
|
+
message: error.message,
|
|
275
|
+
code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",
|
|
276
|
+
cause: error
|
|
277
|
+
});
|
|
278
|
+
} else if (error.name === "SecurityError") {
|
|
279
|
+
const effectiveDomain = window.location.hostname;
|
|
280
|
+
if (!isValidDomain(effectiveDomain)) {
|
|
281
|
+
return new WebAuthnError({
|
|
282
|
+
message: `${window.location.hostname} is an invalid domain`,
|
|
283
|
+
code: "ERROR_INVALID_DOMAIN",
|
|
284
|
+
cause: error
|
|
285
|
+
});
|
|
286
|
+
} else if (publicKey.rpId !== effectiveDomain) {
|
|
287
|
+
return new WebAuthnError({
|
|
288
|
+
message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
|
|
289
|
+
code: "ERROR_INVALID_RP_ID",
|
|
290
|
+
cause: error
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
} else if (error.name === "UnknownError") {
|
|
294
|
+
return new WebAuthnError({
|
|
295
|
+
message: "The authenticator was unable to process the specified options, or could not create a new assertion signature",
|
|
296
|
+
code: "ERROR_AUTHENTICATOR_GENERAL_ERROR",
|
|
297
|
+
cause: error
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return error;
|
|
301
|
+
}
|
|
302
|
+
async function startAuthentication(options) {
|
|
303
|
+
const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true } = options;
|
|
304
|
+
if (!browserSupportsWebAuthn()) {
|
|
305
|
+
throw new Error("WebAuthn is not supported in this browser");
|
|
306
|
+
}
|
|
307
|
+
let allowCredentials;
|
|
308
|
+
if (optionsJSON.allowCredentials?.length !== 0) {
|
|
309
|
+
allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
|
|
310
|
+
}
|
|
311
|
+
const publicKey = {
|
|
312
|
+
...optionsJSON,
|
|
313
|
+
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
314
|
+
allowCredentials
|
|
315
|
+
};
|
|
316
|
+
const getOptions = {};
|
|
317
|
+
if (useBrowserAutofill) {
|
|
318
|
+
if (!await browserSupportsWebAuthnAutofill()) {
|
|
319
|
+
throw Error("Browser does not support WebAuthn autofill");
|
|
320
|
+
}
|
|
321
|
+
const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
|
|
322
|
+
if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
|
|
323
|
+
throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
|
|
324
|
+
}
|
|
325
|
+
getOptions.mediation = "conditional";
|
|
326
|
+
publicKey.allowCredentials = [];
|
|
327
|
+
}
|
|
328
|
+
getOptions.publicKey = publicKey;
|
|
329
|
+
getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
330
|
+
let credential;
|
|
331
|
+
try {
|
|
332
|
+
credential = await navigator.credentials.get(getOptions);
|
|
333
|
+
} catch (err) {
|
|
334
|
+
throw identifyAuthenticationError({ error: err, options: getOptions });
|
|
335
|
+
}
|
|
336
|
+
if (!credential) {
|
|
337
|
+
throw new Error("Authentication was not completed");
|
|
338
|
+
}
|
|
339
|
+
const { id, rawId, response, type } = credential;
|
|
340
|
+
let userHandle = void 0;
|
|
341
|
+
if (response.userHandle) {
|
|
342
|
+
userHandle = bufferToBase64URLString(response.userHandle);
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
id,
|
|
346
|
+
rawId: bufferToBase64URLString(rawId),
|
|
347
|
+
response: {
|
|
348
|
+
authenticatorData: bufferToBase64URLString(response.authenticatorData),
|
|
349
|
+
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
350
|
+
signature: bufferToBase64URLString(response.signature),
|
|
351
|
+
userHandle
|
|
352
|
+
},
|
|
353
|
+
type,
|
|
354
|
+
clientExtensionResults: credential.getClientExtensionResults(),
|
|
355
|
+
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function platformAuthenticatorIsAvailable() {
|
|
359
|
+
if (!browserSupportsWebAuthn()) {
|
|
360
|
+
return new Promise((resolve) => resolve(false));
|
|
361
|
+
}
|
|
362
|
+
return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
|
|
363
|
+
}
|
|
364
|
+
export {
|
|
365
|
+
WebAuthnAbortService,
|
|
366
|
+
WebAuthnError,
|
|
367
|
+
base64URLStringToBuffer,
|
|
368
|
+
browserSupportsWebAuthn,
|
|
369
|
+
browserSupportsWebAuthnAutofill,
|
|
370
|
+
bufferToBase64URLString,
|
|
371
|
+
platformAuthenticatorIsAvailable,
|
|
372
|
+
startAuthentication,
|
|
373
|
+
startRegistration
|
|
374
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertPublishableKey
|
|
3
|
+
} from "./chunk-WQWBJSSS.mjs";
|
|
4
|
+
import {
|
|
5
|
+
TokensModule
|
|
6
|
+
} from "./chunk-UNYDG2L4.mjs";
|
|
7
|
+
import {
|
|
8
|
+
IQAuthError
|
|
9
|
+
} from "./chunk-6I6RM4MN.mjs";
|
|
10
|
+
|
|
11
|
+
// src/ws.ts
|
|
12
|
+
var DEFAULT_COOKIE = "iqauth_at";
|
|
13
|
+
var DEFAULT_SUBPROTOCOL_PREFIX = "iqauth.bearer.";
|
|
14
|
+
var JWT_SHAPE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
15
|
+
var tokensByIssuer = /* @__PURE__ */ new Map();
|
|
16
|
+
function getTokens(issuer) {
|
|
17
|
+
let mod = tokensByIssuer.get(issuer);
|
|
18
|
+
if (!mod) {
|
|
19
|
+
mod = new TokensModule(issuer);
|
|
20
|
+
tokensByIssuer.set(issuer, mod);
|
|
21
|
+
}
|
|
22
|
+
return mod;
|
|
23
|
+
}
|
|
24
|
+
function firstHeader(value) {
|
|
25
|
+
if (Array.isArray(value)) return value[0];
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function readCookie(cookieHeader, name) {
|
|
29
|
+
if (!cookieHeader) return void 0;
|
|
30
|
+
const target = `${name}=`;
|
|
31
|
+
for (const seg of cookieHeader.split(";")) {
|
|
32
|
+
const t = seg.trim();
|
|
33
|
+
if (t.startsWith(target)) {
|
|
34
|
+
try {
|
|
35
|
+
return decodeURIComponent(t.slice(target.length));
|
|
36
|
+
} catch {
|
|
37
|
+
return t.slice(target.length);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
function extractToken(req, cookieName, subprotocolPrefix) {
|
|
44
|
+
let authHeader;
|
|
45
|
+
let cookieHeader;
|
|
46
|
+
let subprotoHeader;
|
|
47
|
+
if ("headers" in req && req.headers && typeof req.headers === "object") {
|
|
48
|
+
authHeader = firstHeader(req.headers.authorization);
|
|
49
|
+
cookieHeader = firstHeader(req.headers.cookie);
|
|
50
|
+
subprotoHeader = firstHeader(req.headers["sec-websocket-protocol"]);
|
|
51
|
+
} else {
|
|
52
|
+
const r = req;
|
|
53
|
+
authHeader = r.authorization;
|
|
54
|
+
cookieHeader = r.cookie;
|
|
55
|
+
subprotoHeader = r.secWebSocketProtocol;
|
|
56
|
+
}
|
|
57
|
+
if (authHeader && /^Bearer /i.test(authHeader)) {
|
|
58
|
+
return authHeader.slice(7).trim();
|
|
59
|
+
}
|
|
60
|
+
if (cookieName && cookieHeader) {
|
|
61
|
+
const fromCookie = readCookie(cookieHeader, cookieName);
|
|
62
|
+
if (fromCookie) return fromCookie;
|
|
63
|
+
}
|
|
64
|
+
if (subprotocolPrefix !== null && subprotoHeader) {
|
|
65
|
+
const protos = subprotoHeader.split(",").map((s) => s.trim()).filter(Boolean);
|
|
66
|
+
for (const proto of protos) {
|
|
67
|
+
if (subprotocolPrefix && proto.startsWith(subprotocolPrefix)) {
|
|
68
|
+
return proto.slice(subprotocolPrefix.length);
|
|
69
|
+
}
|
|
70
|
+
if (JWT_SHAPE.test(proto)) return proto;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
async function verifyWsUpgrade(req, options) {
|
|
76
|
+
const parsed = assertPublishableKey(options.publishableKey, {
|
|
77
|
+
context: "@iqauth/sdk/ws"
|
|
78
|
+
});
|
|
79
|
+
const issuer = (options.issuer && typeof options.issuer === "string" ? options.issuer : parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`).replace(/\/+$/, "");
|
|
80
|
+
const cookieName = options.cookieName === void 0 ? DEFAULT_COOKIE : options.cookieName;
|
|
81
|
+
const subprotocolPrefix = options.subprotocolPrefix === void 0 ? DEFAULT_SUBPROTOCOL_PREFIX : options.subprotocolPrefix;
|
|
82
|
+
const token = extractToken(req, cookieName, subprotocolPrefix);
|
|
83
|
+
if (!token) return null;
|
|
84
|
+
const tokens = getTokens(issuer);
|
|
85
|
+
try {
|
|
86
|
+
const verifyOpts = {};
|
|
87
|
+
if (options.audience !== void 0) verifyOpts.audience = options.audience;
|
|
88
|
+
verifyOpts.issuer = options.issuer ?? issuer;
|
|
89
|
+
if (options.clockTolerance !== void 0)
|
|
90
|
+
verifyOpts.clockTolerance = options.clockTolerance;
|
|
91
|
+
if (options.algorithms !== void 0) verifyOpts.algorithms = options.algorithms;
|
|
92
|
+
const claims = await tokens.verify(token, verifyOpts);
|
|
93
|
+
return { claims };
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof IQAuthError) return null;
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function _resetWsVerifierCache() {
|
|
100
|
+
tokensByIssuer.clear();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
verifyWsUpgrade,
|
|
105
|
+
_resetWsVerifierCache
|
|
106
|
+
};
|