@supabase/auth-js 2.73.0-rc.3 → 2.73.0-rc.5
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/main/GoTrueClient.d.ts +1 -1
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +43 -15
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/base64url.d.ts +3 -2
- package/dist/main/lib/base64url.d.ts.map +1 -1
- package/dist/main/lib/base64url.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +2 -1
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types.d.ts +140 -19
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js +3 -2
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/webauthn.d.ts +274 -0
- package/dist/main/lib/webauthn.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.d.ts +583 -0
- package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/main/lib/webauthn.dom.js +4 -0
- package/dist/main/lib/webauthn.dom.js.map +1 -0
- package/dist/main/lib/webauthn.errors.d.ts +80 -0
- package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/main/lib/webauthn.errors.js +265 -0
- package/dist/main/lib/webauthn.errors.js.map +1 -0
- package/dist/main/lib/webauthn.js +702 -0
- package/dist/main/lib/webauthn.js.map +1 -0
- package/dist/module/GoTrueClient.d.ts +1 -1
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +49 -21
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/base64url.d.ts +3 -2
- package/dist/module/lib/base64url.d.ts.map +1 -1
- package/dist/module/lib/base64url.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +2 -1
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/types.d.ts +140 -19
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js +2 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/webauthn.d.ts +274 -0
- package/dist/module/lib/webauthn.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.d.ts +583 -0
- package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
- package/dist/module/lib/webauthn.dom.js +3 -0
- package/dist/module/lib/webauthn.dom.js.map +1 -0
- package/dist/module/lib/webauthn.errors.d.ts +80 -0
- package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
- package/dist/module/lib/webauthn.errors.js +257 -0
- package/dist/module/lib/webauthn.errors.js.map +1 -0
- package/dist/module/lib/webauthn.js +685 -0
- package/dist/module/lib/webauthn.js.map +1 -0
- package/package.json +1 -1
- package/src/GoTrueClient.ts +198 -68
- package/src/lib/base64url.ts +4 -2
- package/src/lib/helpers.ts +2 -1
- package/src/lib/types.ts +205 -26
- package/src/lib/version.ts +1 -1
- package/src/lib/webauthn.dom.ts +636 -0
- package/src/lib/webauthn.errors.ts +317 -0
- package/src/lib/webauthn.ts +929 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { StrictOmit } from './types';
|
|
2
|
+
import { PublicKeyCredentialCreationOptionsFuture, PublicKeyCredentialRequestOptionsFuture } from './webauthn.dom';
|
|
3
|
+
/**
|
|
4
|
+
* A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
|
|
5
|
+
* errors in the spec was raised after calling `navigator.credentials.create()` or
|
|
6
|
+
* `navigator.credentials.get()`:
|
|
7
|
+
*
|
|
8
|
+
* - `AbortError`
|
|
9
|
+
* - `ConstraintError`
|
|
10
|
+
* - `InvalidStateError`
|
|
11
|
+
* - `NotAllowedError`
|
|
12
|
+
* - `NotSupportedError`
|
|
13
|
+
* - `SecurityError`
|
|
14
|
+
* - `TypeError`
|
|
15
|
+
* - `UnknownError`
|
|
16
|
+
*
|
|
17
|
+
* Error messages were determined through investigation of the spec to determine under which
|
|
18
|
+
* scenarios a given error would be raised.
|
|
19
|
+
*/
|
|
20
|
+
export declare class WebAuthnError extends Error {
|
|
21
|
+
code: WebAuthnErrorCode;
|
|
22
|
+
protected __isWebAuthnError: boolean;
|
|
23
|
+
constructor({ message, code, cause, name, }: {
|
|
24
|
+
message: string;
|
|
25
|
+
code: WebAuthnErrorCode;
|
|
26
|
+
cause?: Error | unknown;
|
|
27
|
+
name?: string;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Error class for unknown WebAuthn errors.
|
|
32
|
+
* Wraps unexpected errors that don't match known WebAuthn error conditions.
|
|
33
|
+
*/
|
|
34
|
+
export declare class WebAuthnUnknownError extends WebAuthnError {
|
|
35
|
+
originalError: unknown;
|
|
36
|
+
constructor(message: string, originalError: unknown);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type guard to check if an error is a WebAuthnError.
|
|
40
|
+
* @param {unknown} error - The error to check
|
|
41
|
+
* @returns {boolean} True if the error is a WebAuthnError
|
|
42
|
+
*/
|
|
43
|
+
export declare function isWebAuthnError(error: unknown): error is WebAuthnError;
|
|
44
|
+
/**
|
|
45
|
+
* Error codes for WebAuthn operations.
|
|
46
|
+
* These codes provide specific information about why a WebAuthn ceremony failed.
|
|
47
|
+
* @see {@link https://w3c.github.io/webauthn/#sctn-defined-errors W3C WebAuthn Spec - Defined Errors}
|
|
48
|
+
*/
|
|
49
|
+
export declare type WebAuthnErrorCode = 'ERROR_CEREMONY_ABORTED' | 'ERROR_INVALID_DOMAIN' | 'ERROR_INVALID_RP_ID' | 'ERROR_INVALID_USER_ID_LENGTH' | 'ERROR_MALFORMED_PUBKEYCREDPARAMS' | 'ERROR_AUTHENTICATOR_GENERAL_ERROR' | 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT' | 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT' | 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED' | 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG' | 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE' | 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY';
|
|
50
|
+
/**
|
|
51
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`.
|
|
52
|
+
* Maps browser errors to specific WebAuthn error codes for better debugging.
|
|
53
|
+
* @param {Object} params - Error identification parameters
|
|
54
|
+
* @param {Error} params.error - The error thrown by the browser
|
|
55
|
+
* @param {CredentialCreationOptions} params.options - The options passed to credentials.create()
|
|
56
|
+
* @returns {WebAuthnError} A WebAuthnError with a specific error code
|
|
57
|
+
* @see {@link https://w3c.github.io/webauthn/#sctn-createCredential W3C WebAuthn Spec - Create Credential}
|
|
58
|
+
*/
|
|
59
|
+
export declare function identifyRegistrationError({ error, options, }: {
|
|
60
|
+
error: Error;
|
|
61
|
+
options: StrictOmit<CredentialCreationOptions, 'publicKey'> & {
|
|
62
|
+
publicKey: PublicKeyCredentialCreationOptionsFuture;
|
|
63
|
+
};
|
|
64
|
+
}): WebAuthnError;
|
|
65
|
+
/**
|
|
66
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`.
|
|
67
|
+
* Maps browser errors to specific WebAuthn error codes for better debugging.
|
|
68
|
+
* @param {Object} params - Error identification parameters
|
|
69
|
+
* @param {Error} params.error - The error thrown by the browser
|
|
70
|
+
* @param {CredentialRequestOptions} params.options - The options passed to credentials.get()
|
|
71
|
+
* @returns {WebAuthnError} A WebAuthnError with a specific error code
|
|
72
|
+
* @see {@link https://w3c.github.io/webauthn/#sctn-getAssertion W3C WebAuthn Spec - Get Assertion}
|
|
73
|
+
*/
|
|
74
|
+
export declare function identifyAuthenticationError({ error, options, }: {
|
|
75
|
+
error: Error;
|
|
76
|
+
options: StrictOmit<CredentialRequestOptions, 'publicKey'> & {
|
|
77
|
+
publicKey: PublicKeyCredentialRequestOptionsFuture;
|
|
78
|
+
};
|
|
79
|
+
}): WebAuthnError;
|
|
80
|
+
//# sourceMappingURL=webauthn.errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.errors.d.ts","sourceRoot":"","sources":["../../../src/lib/webauthn.errors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,EACL,wCAAwC,EACxC,uCAAuC,EACxC,MAAM,gBAAgB,CAAA;AAEvB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,iBAAiB,CAAA;IAEvB,SAAS,CAAC,iBAAiB,UAAO;gBAEtB,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAI,GACL,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,EAAE,iBAAiB,CAAA;QACvB,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd;CAMF;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,aAAa,EAAE,OAAO,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO;CASpD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;GAIG;AACH,oBAAY,iBAAiB,GACzB,wBAAwB,GACxB,sBAAsB,GACtB,qBAAqB,GACrB,8BAA8B,GAC9B,kCAAkC,GAClC,mCAAmC,GACnC,6DAA6D,GAC7D,uDAAuD,GACvD,2CAA2C,GAC3C,uDAAuD,GACvD,+CAA+C,GAC/C,sCAAsC,CAAA;AAE1C;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,UAAU,CAAC,yBAAyB,EAAE,WAAW,CAAC,GAAG;QAC5D,SAAS,EAAE,wCAAwC,CAAA;KACpD,CAAA;CACF,GAAG,aAAa,CA8HhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,UAAU,CAAC,wBAAwB,EAAE,WAAW,CAAC,GAAG;QAC3D,SAAS,EAAE,uCAAuC,CAAA;KACnD,CAAA;CACF,GAAG,aAAa,CA2DhB"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.identifyAuthenticationError = exports.identifyRegistrationError = exports.isWebAuthnError = exports.WebAuthnUnknownError = exports.WebAuthnError = void 0;
|
|
5
|
+
const webauthn_1 = require("./webauthn");
|
|
6
|
+
/**
|
|
7
|
+
* A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
|
|
8
|
+
* errors in the spec was raised after calling `navigator.credentials.create()` or
|
|
9
|
+
* `navigator.credentials.get()`:
|
|
10
|
+
*
|
|
11
|
+
* - `AbortError`
|
|
12
|
+
* - `ConstraintError`
|
|
13
|
+
* - `InvalidStateError`
|
|
14
|
+
* - `NotAllowedError`
|
|
15
|
+
* - `NotSupportedError`
|
|
16
|
+
* - `SecurityError`
|
|
17
|
+
* - `TypeError`
|
|
18
|
+
* - `UnknownError`
|
|
19
|
+
*
|
|
20
|
+
* Error messages were determined through investigation of the spec to determine under which
|
|
21
|
+
* scenarios a given error would be raised.
|
|
22
|
+
*/
|
|
23
|
+
class WebAuthnError extends Error {
|
|
24
|
+
constructor({ message, code, cause, name, }) {
|
|
25
|
+
var _a;
|
|
26
|
+
// @ts-ignore: help Rollup understand that `cause` is okay to set
|
|
27
|
+
super(message, { cause });
|
|
28
|
+
this.__isWebAuthnError = true;
|
|
29
|
+
this.name = (_a = name !== null && name !== void 0 ? name : (cause instanceof Error ? cause.name : undefined)) !== null && _a !== void 0 ? _a : 'Unknown Error';
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.WebAuthnError = WebAuthnError;
|
|
34
|
+
/**
|
|
35
|
+
* Error class for unknown WebAuthn errors.
|
|
36
|
+
* Wraps unexpected errors that don't match known WebAuthn error conditions.
|
|
37
|
+
*/
|
|
38
|
+
class WebAuthnUnknownError extends WebAuthnError {
|
|
39
|
+
constructor(message, originalError) {
|
|
40
|
+
super({
|
|
41
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
42
|
+
cause: originalError,
|
|
43
|
+
message,
|
|
44
|
+
});
|
|
45
|
+
this.name = 'WebAuthnUnknownError';
|
|
46
|
+
this.originalError = originalError;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.WebAuthnUnknownError = WebAuthnUnknownError;
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if an error is a WebAuthnError.
|
|
52
|
+
* @param {unknown} error - The error to check
|
|
53
|
+
* @returns {boolean} True if the error is a WebAuthnError
|
|
54
|
+
*/
|
|
55
|
+
function isWebAuthnError(error) {
|
|
56
|
+
return typeof error === 'object' && error !== null && '__isWebAuthnError' in error;
|
|
57
|
+
}
|
|
58
|
+
exports.isWebAuthnError = isWebAuthnError;
|
|
59
|
+
/**
|
|
60
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`.
|
|
61
|
+
* Maps browser errors to specific WebAuthn error codes for better debugging.
|
|
62
|
+
* @param {Object} params - Error identification parameters
|
|
63
|
+
* @param {Error} params.error - The error thrown by the browser
|
|
64
|
+
* @param {CredentialCreationOptions} params.options - The options passed to credentials.create()
|
|
65
|
+
* @returns {WebAuthnError} A WebAuthnError with a specific error code
|
|
66
|
+
* @see {@link https://w3c.github.io/webauthn/#sctn-createCredential W3C WebAuthn Spec - Create Credential}
|
|
67
|
+
*/
|
|
68
|
+
function identifyRegistrationError({ error, options, }) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const { publicKey } = options;
|
|
71
|
+
if (!publicKey) {
|
|
72
|
+
throw Error('options was missing required publicKey property');
|
|
73
|
+
}
|
|
74
|
+
if (error.name === 'AbortError') {
|
|
75
|
+
if (options.signal instanceof AbortSignal) {
|
|
76
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
|
|
77
|
+
return new WebAuthnError({
|
|
78
|
+
message: 'Registration ceremony was sent an abort signal',
|
|
79
|
+
code: 'ERROR_CEREMONY_ABORTED',
|
|
80
|
+
cause: error,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (error.name === 'ConstraintError') {
|
|
85
|
+
if (((_a = publicKey.authenticatorSelection) === null || _a === void 0 ? void 0 : _a.requireResidentKey) === true) {
|
|
86
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
|
|
87
|
+
return new WebAuthnError({
|
|
88
|
+
message: 'Discoverable credentials were required but no available authenticator supported it',
|
|
89
|
+
code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
|
|
90
|
+
cause: error,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (
|
|
94
|
+
// @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
|
|
95
|
+
options.mediation === 'conditional' &&
|
|
96
|
+
((_b = publicKey.authenticatorSelection) === null || _b === void 0 ? void 0 : _b.userVerification) === 'required') {
|
|
97
|
+
// https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
|
|
98
|
+
return new WebAuthnError({
|
|
99
|
+
message: 'User verification was required during automatic registration but it could not be performed',
|
|
100
|
+
code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
|
|
101
|
+
cause: error,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else if (((_c = publicKey.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.userVerification) === 'required') {
|
|
105
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
|
|
106
|
+
return new WebAuthnError({
|
|
107
|
+
message: 'User verification was required but no available authenticator supported it',
|
|
108
|
+
code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
|
|
109
|
+
cause: error,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (error.name === 'InvalidStateError') {
|
|
114
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
|
|
115
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
|
|
116
|
+
return new WebAuthnError({
|
|
117
|
+
message: 'The authenticator was previously registered',
|
|
118
|
+
code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
|
|
119
|
+
cause: error,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else if (error.name === 'NotAllowedError') {
|
|
123
|
+
/**
|
|
124
|
+
* Pass the error directly through. Platforms are overloading this error beyond what the spec
|
|
125
|
+
* defines and we don't want to overwrite potentially useful error messages.
|
|
126
|
+
*/
|
|
127
|
+
return new WebAuthnError({
|
|
128
|
+
message: error.message,
|
|
129
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
130
|
+
cause: error,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else if (error.name === 'NotSupportedError') {
|
|
134
|
+
const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
|
|
135
|
+
if (validPubKeyCredParams.length === 0) {
|
|
136
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
|
|
137
|
+
return new WebAuthnError({
|
|
138
|
+
message: 'No entry in pubKeyCredParams was of type "public-key"',
|
|
139
|
+
code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
|
|
140
|
+
cause: error,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
|
|
144
|
+
return new WebAuthnError({
|
|
145
|
+
message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
|
|
146
|
+
code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
|
|
147
|
+
cause: error,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (error.name === 'SecurityError') {
|
|
151
|
+
const effectiveDomain = window.location.hostname;
|
|
152
|
+
if (!(0, webauthn_1.isValidDomain)(effectiveDomain)) {
|
|
153
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
|
|
154
|
+
return new WebAuthnError({
|
|
155
|
+
message: `${window.location.hostname} is an invalid domain`,
|
|
156
|
+
code: 'ERROR_INVALID_DOMAIN',
|
|
157
|
+
cause: error,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else if (publicKey.rp.id !== effectiveDomain) {
|
|
161
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
|
|
162
|
+
return new WebAuthnError({
|
|
163
|
+
message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
|
|
164
|
+
code: 'ERROR_INVALID_RP_ID',
|
|
165
|
+
cause: error,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (error.name === 'TypeError') {
|
|
170
|
+
if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
|
|
171
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
|
|
172
|
+
return new WebAuthnError({
|
|
173
|
+
message: 'User ID was not between 1 and 64 characters',
|
|
174
|
+
code: 'ERROR_INVALID_USER_ID_LENGTH',
|
|
175
|
+
cause: error,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (error.name === 'UnknownError') {
|
|
180
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
|
|
181
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
|
|
182
|
+
return new WebAuthnError({
|
|
183
|
+
message: 'The authenticator was unable to process the specified options, or could not create a new credential',
|
|
184
|
+
code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
185
|
+
cause: error,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return new WebAuthnError({
|
|
189
|
+
message: 'a Non-Webauthn related error has occurred',
|
|
190
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
191
|
+
cause: error,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
exports.identifyRegistrationError = identifyRegistrationError;
|
|
195
|
+
/**
|
|
196
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`.
|
|
197
|
+
* Maps browser errors to specific WebAuthn error codes for better debugging.
|
|
198
|
+
* @param {Object} params - Error identification parameters
|
|
199
|
+
* @param {Error} params.error - The error thrown by the browser
|
|
200
|
+
* @param {CredentialRequestOptions} params.options - The options passed to credentials.get()
|
|
201
|
+
* @returns {WebAuthnError} A WebAuthnError with a specific error code
|
|
202
|
+
* @see {@link https://w3c.github.io/webauthn/#sctn-getAssertion W3C WebAuthn Spec - Get Assertion}
|
|
203
|
+
*/
|
|
204
|
+
function identifyAuthenticationError({ error, options, }) {
|
|
205
|
+
const { publicKey } = options;
|
|
206
|
+
if (!publicKey) {
|
|
207
|
+
throw Error('options was missing required publicKey property');
|
|
208
|
+
}
|
|
209
|
+
if (error.name === 'AbortError') {
|
|
210
|
+
if (options.signal instanceof AbortSignal) {
|
|
211
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
|
|
212
|
+
return new WebAuthnError({
|
|
213
|
+
message: 'Authentication ceremony was sent an abort signal',
|
|
214
|
+
code: 'ERROR_CEREMONY_ABORTED',
|
|
215
|
+
cause: error,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (error.name === 'NotAllowedError') {
|
|
220
|
+
/**
|
|
221
|
+
* Pass the error directly through. Platforms are overloading this error beyond what the spec
|
|
222
|
+
* defines and we don't want to overwrite potentially useful error messages.
|
|
223
|
+
*/
|
|
224
|
+
return new WebAuthnError({
|
|
225
|
+
message: error.message,
|
|
226
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
227
|
+
cause: error,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else if (error.name === 'SecurityError') {
|
|
231
|
+
const effectiveDomain = window.location.hostname;
|
|
232
|
+
if (!(0, webauthn_1.isValidDomain)(effectiveDomain)) {
|
|
233
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
|
|
234
|
+
return new WebAuthnError({
|
|
235
|
+
message: `${window.location.hostname} is an invalid domain`,
|
|
236
|
+
code: 'ERROR_INVALID_DOMAIN',
|
|
237
|
+
cause: error,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else if (publicKey.rpId !== effectiveDomain) {
|
|
241
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
|
|
242
|
+
return new WebAuthnError({
|
|
243
|
+
message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
|
|
244
|
+
code: 'ERROR_INVALID_RP_ID',
|
|
245
|
+
cause: error,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else if (error.name === 'UnknownError') {
|
|
250
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
|
|
251
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
|
|
252
|
+
return new WebAuthnError({
|
|
253
|
+
message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
|
|
254
|
+
code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
255
|
+
cause: error,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return new WebAuthnError({
|
|
259
|
+
message: 'a Non-Webauthn related error has occurred',
|
|
260
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
261
|
+
cause: error,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
exports.identifyAuthenticationError = identifyAuthenticationError;
|
|
265
|
+
//# sourceMappingURL=webauthn.errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.errors.js","sourceRoot":"","sources":["../../../src/lib/webauthn.errors.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;AAGtD,yCAA0C;AAM1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,aAAc,SAAQ,KAAK;IAKtC,YAAY,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAI,GAML;;QACC,iEAAiE;QACjE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAdjB,sBAAiB,GAAG,IAAI,CAAA;QAehC,IAAI,CAAC,IAAI,GAAG,MAAA,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,mCAAI,eAAe,CAAA;QACxF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AArBD,sCAqBC;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,aAAa;IAGrD,YAAY,OAAe,EAAE,aAAsB;QACjD,KAAK,CAAC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