@palbase/web 7.0.0 → 7.1.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/dist/{analytics-facade-CdTK9Y0s.d.ts → analytics-facade-CZIwbsvG.d.ts} +23 -0
- package/dist/{analytics-facade-TB-D4ww8.d.cts → analytics-facade-esr6cOBN.d.cts} +23 -0
- package/dist/{chunk-7SNSLY5M.js → chunk-P6TWUWZC.js} +191 -2
- package/dist/chunk-P6TWUWZC.js.map +1 -0
- package/dist/index.cjs +190 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/internal.cjs +190 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +3 -3
- package/dist/internal.d.ts +3 -3
- package/dist/internal.js +1 -1
- package/dist/next/client.cjs +190 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/index.cjs +190 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -2
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +1 -1
- package/dist/{pb-B6ZcZy8v.d.ts → pb-AWwslm5m.d.ts} +1 -1
- package/dist/{pb-CiSj4lM3.d.cts → pb-BT-vKA4j.d.cts} +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-7SNSLY5M.js.map +0 -1
|
@@ -1839,6 +1839,29 @@ declare class PalbeAuth {
|
|
|
1839
1839
|
provider: string;
|
|
1840
1840
|
credential: string;
|
|
1841
1841
|
}): Promise<AuthSuccess>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Sign in with a passkey stored for this Environment. No identifier is typed:
|
|
1844
|
+
* the browser lists the accounts it holds and the user picks one.
|
|
1845
|
+
*
|
|
1846
|
+
* Throws when the browser cannot run a ceremony — check `passkeysSupported`
|
|
1847
|
+
* first and keep a password or e-mail path beside the button.
|
|
1848
|
+
*/
|
|
1849
|
+
signInWithPasskey(): Promise<AuthSuccess>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Create an account whose only credential is a passkey — the e-mail is the
|
|
1852
|
+
* identifier, the passkey is the credential, and no password ever exists.
|
|
1853
|
+
*/
|
|
1854
|
+
signUpWithPasskey(email: string, displayName?: string): Promise<AuthSuccess>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Add a passkey to the signed-in account, so the next sign-in is one tap.
|
|
1857
|
+
*
|
|
1858
|
+
* Rejects with a 403 `reauthentication_required` when the session is not
|
|
1859
|
+
* recent: a passkey outlives a password reset, so enrolling one takes more
|
|
1860
|
+
* than a valid session.
|
|
1861
|
+
*/
|
|
1862
|
+
registerPasskey(name?: string): Promise<void>;
|
|
1863
|
+
/** Whether this browser can run a passkey ceremony at all. */
|
|
1864
|
+
get passkeysSupported(): boolean;
|
|
1842
1865
|
signInWithOAuth(params: {
|
|
1843
1866
|
provider: string;
|
|
1844
1867
|
redirectTo?: string;
|
|
@@ -1839,6 +1839,29 @@ declare class PalbeAuth {
|
|
|
1839
1839
|
provider: string;
|
|
1840
1840
|
credential: string;
|
|
1841
1841
|
}): Promise<AuthSuccess>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Sign in with a passkey stored for this Environment. No identifier is typed:
|
|
1844
|
+
* the browser lists the accounts it holds and the user picks one.
|
|
1845
|
+
*
|
|
1846
|
+
* Throws when the browser cannot run a ceremony — check `passkeysSupported`
|
|
1847
|
+
* first and keep a password or e-mail path beside the button.
|
|
1848
|
+
*/
|
|
1849
|
+
signInWithPasskey(): Promise<AuthSuccess>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Create an account whose only credential is a passkey — the e-mail is the
|
|
1852
|
+
* identifier, the passkey is the credential, and no password ever exists.
|
|
1853
|
+
*/
|
|
1854
|
+
signUpWithPasskey(email: string, displayName?: string): Promise<AuthSuccess>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Add a passkey to the signed-in account, so the next sign-in is one tap.
|
|
1857
|
+
*
|
|
1858
|
+
* Rejects with a 403 `reauthentication_required` when the session is not
|
|
1859
|
+
* recent: a passkey outlives a password reset, so enrolling one takes more
|
|
1860
|
+
* than a valid session.
|
|
1861
|
+
*/
|
|
1862
|
+
registerPasskey(name?: string): Promise<void>;
|
|
1863
|
+
/** Whether this browser can run a passkey ceremony at all. */
|
|
1864
|
+
get passkeysSupported(): boolean;
|
|
1842
1865
|
signInWithOAuth(params: {
|
|
1843
1866
|
provider: string;
|
|
1844
1867
|
redirectTo?: string;
|
|
@@ -1048,6 +1048,162 @@ function asWireAuthResult(raw) {
|
|
|
1048
1048
|
return raw;
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
|
+
// src/passkey.ts
|
|
1052
|
+
function base64UrlToBytes(value) {
|
|
1053
|
+
const padded = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
1054
|
+
const binary = atob(padded.padEnd(padded.length + (4 - padded.length % 4) % 4, "="));
|
|
1055
|
+
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
|
|
1056
|
+
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
1057
|
+
return bytes;
|
|
1058
|
+
}
|
|
1059
|
+
function bytesToBase64Url(buffer) {
|
|
1060
|
+
const bytes = new Uint8Array(buffer);
|
|
1061
|
+
let binary = "";
|
|
1062
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
1063
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1064
|
+
}
|
|
1065
|
+
function requireString(source, key) {
|
|
1066
|
+
const value = source[key];
|
|
1067
|
+
if (typeof value !== "string" || value === "") {
|
|
1068
|
+
throw new Error(`passkey options are missing ${key}`);
|
|
1069
|
+
}
|
|
1070
|
+
return value;
|
|
1071
|
+
}
|
|
1072
|
+
function toCreationOptions(publicKey) {
|
|
1073
|
+
const rp = publicKey.rp;
|
|
1074
|
+
const user = publicKey.user;
|
|
1075
|
+
if (!user?.id) {
|
|
1076
|
+
throw new Error("passkey options carry no user id \u2014 the credential would be unusable");
|
|
1077
|
+
}
|
|
1078
|
+
const excludeCredentials = Array.isArray(publicKey.excludeCredentials) ? publicKey.excludeCredentials.map((c) => ({
|
|
1079
|
+
id: base64UrlToBytes(c.id),
|
|
1080
|
+
type: "public-key"
|
|
1081
|
+
})) : void 0;
|
|
1082
|
+
return {
|
|
1083
|
+
challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
|
|
1084
|
+
rp: { id: rp?.id, name: rp?.name ?? rp?.id ?? "" },
|
|
1085
|
+
user: {
|
|
1086
|
+
id: base64UrlToBytes(user.id),
|
|
1087
|
+
name: user.name ?? "",
|
|
1088
|
+
displayName: user.displayName ?? user.name ?? ""
|
|
1089
|
+
},
|
|
1090
|
+
pubKeyCredParams: publicKey.pubKeyCredParams ?? [],
|
|
1091
|
+
authenticatorSelection: publicKey.authenticatorSelection,
|
|
1092
|
+
timeout: publicKey.timeout,
|
|
1093
|
+
attestation: publicKey.attestation,
|
|
1094
|
+
excludeCredentials
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
function toRequestOptions(publicKey) {
|
|
1098
|
+
const allowCredentials = Array.isArray(publicKey.allowCredentials) ? publicKey.allowCredentials.map((c) => ({
|
|
1099
|
+
id: base64UrlToBytes(c.id),
|
|
1100
|
+
type: "public-key"
|
|
1101
|
+
})) : void 0;
|
|
1102
|
+
return {
|
|
1103
|
+
challenge: base64UrlToBytes(requireString(publicKey, "challenge")),
|
|
1104
|
+
rpId: publicKey.rpId,
|
|
1105
|
+
timeout: publicKey.timeout,
|
|
1106
|
+
userVerification: publicKey.userVerification,
|
|
1107
|
+
allowCredentials
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function attestationToJSON(credential) {
|
|
1111
|
+
const response = credential.response;
|
|
1112
|
+
return {
|
|
1113
|
+
id: credential.id,
|
|
1114
|
+
rawId: bytesToBase64Url(credential.rawId),
|
|
1115
|
+
type: credential.type,
|
|
1116
|
+
response: {
|
|
1117
|
+
clientDataJSON: bytesToBase64Url(response.clientDataJSON),
|
|
1118
|
+
attestationObject: bytesToBase64Url(response.attestationObject)
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
function assertionToJSON(credential) {
|
|
1123
|
+
const response = credential.response;
|
|
1124
|
+
return {
|
|
1125
|
+
id: credential.id,
|
|
1126
|
+
rawId: bytesToBase64Url(credential.rawId),
|
|
1127
|
+
type: credential.type,
|
|
1128
|
+
response: {
|
|
1129
|
+
clientDataJSON: bytesToBase64Url(response.clientDataJSON),
|
|
1130
|
+
authenticatorData: bytesToBase64Url(response.authenticatorData),
|
|
1131
|
+
signature: bytesToBase64Url(response.signature),
|
|
1132
|
+
// The user handle is how palauth resolves WHO signed in on a discoverable
|
|
1133
|
+
// login — there is no identifier in the request.
|
|
1134
|
+
userHandle: response.userHandle ? bytesToBase64Url(response.userHandle) : null
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function isPasskeySupported() {
|
|
1139
|
+
return typeof window !== "undefined" && typeof window.PublicKeyCredential === "function" && typeof navigator !== "undefined" && navigator.credentials !== void 0;
|
|
1140
|
+
}
|
|
1141
|
+
function ensureSupported() {
|
|
1142
|
+
if (!isPasskeySupported()) {
|
|
1143
|
+
throw new Error("This browser cannot use passkeys \u2014 offer a password or e-mail sign-in");
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
async function createCredential(publicKey) {
|
|
1147
|
+
const credential = await navigator.credentials.create({
|
|
1148
|
+
publicKey: toCreationOptions(publicKey)
|
|
1149
|
+
});
|
|
1150
|
+
if (credential === null) {
|
|
1151
|
+
throw new Error("the browser returned no credential");
|
|
1152
|
+
}
|
|
1153
|
+
return credential;
|
|
1154
|
+
}
|
|
1155
|
+
async function getCredential(publicKey) {
|
|
1156
|
+
const credential = await navigator.credentials.get({
|
|
1157
|
+
publicKey: toRequestOptions(publicKey)
|
|
1158
|
+
});
|
|
1159
|
+
if (credential === null) {
|
|
1160
|
+
throw new Error("the browser returned no credential");
|
|
1161
|
+
}
|
|
1162
|
+
return credential;
|
|
1163
|
+
}
|
|
1164
|
+
async function passkeySignIn(rt) {
|
|
1165
|
+
ensureSupported();
|
|
1166
|
+
const envelope = await palbeRequest(rt, "POST", "/auth/webauthn/login/begin", {
|
|
1167
|
+
body: {}
|
|
1168
|
+
});
|
|
1169
|
+
const credential = await getCredential(envelope.options.publicKey);
|
|
1170
|
+
const raw = await palbeRequest(rt, "POST", "/auth/webauthn/login/finish", {
|
|
1171
|
+
body: assertionToJSON(credential)
|
|
1172
|
+
});
|
|
1173
|
+
const result = asWireAuthResult(raw);
|
|
1174
|
+
if (result === null) {
|
|
1175
|
+
throw new Error("passkey sign-in returned an unusable session");
|
|
1176
|
+
}
|
|
1177
|
+
return result;
|
|
1178
|
+
}
|
|
1179
|
+
async function passkeySignUp(rt, email, displayName) {
|
|
1180
|
+
ensureSupported();
|
|
1181
|
+
const begun = await palbeRequest(rt, "POST", "/auth/webauthn/signup/begin", {
|
|
1182
|
+
body: { email, user_name: displayName }
|
|
1183
|
+
});
|
|
1184
|
+
const credential = await createCredential(begun.options.publicKey);
|
|
1185
|
+
await palbeRequest(
|
|
1186
|
+
rt,
|
|
1187
|
+
"POST",
|
|
1188
|
+
`/auth/webauthn/signup/finish?user_id=${encodeURIComponent(begun.user_id)}`,
|
|
1189
|
+
{ body: attestationToJSON(credential) }
|
|
1190
|
+
);
|
|
1191
|
+
return await passkeySignIn(rt);
|
|
1192
|
+
}
|
|
1193
|
+
async function passkeyRegister(rt, name) {
|
|
1194
|
+
ensureSupported();
|
|
1195
|
+
const envelope = await palbeRequest(
|
|
1196
|
+
rt,
|
|
1197
|
+
"POST",
|
|
1198
|
+
"/auth/webauthn/register/begin",
|
|
1199
|
+
{ body: { name } }
|
|
1200
|
+
);
|
|
1201
|
+
const credential = await createCredential(envelope.options.publicKey);
|
|
1202
|
+
await palbeRequest(rt, "POST", "/auth/webauthn/register/finish", {
|
|
1203
|
+
body: attestationToJSON(credential)
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1051
1207
|
// src/auth-facade.ts
|
|
1052
1208
|
function mapWireUser(raw) {
|
|
1053
1209
|
return {
|
|
@@ -1402,6 +1558,39 @@ var PalbeAuth = class {
|
|
|
1402
1558
|
return this.adopt(data);
|
|
1403
1559
|
});
|
|
1404
1560
|
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Sign in with a passkey stored for this Environment. No identifier is typed:
|
|
1563
|
+
* the browser lists the accounts it holds and the user picks one.
|
|
1564
|
+
*
|
|
1565
|
+
* Throws when the browser cannot run a ceremony — check `passkeysSupported`
|
|
1566
|
+
* first and keep a password or e-mail path beside the button.
|
|
1567
|
+
*/
|
|
1568
|
+
async signInWithPasskey() {
|
|
1569
|
+
return this.withSigningIn(async () => this.adoptWire(await passkeySignIn(this.rt)));
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* Create an account whose only credential is a passkey — the e-mail is the
|
|
1573
|
+
* identifier, the passkey is the credential, and no password ever exists.
|
|
1574
|
+
*/
|
|
1575
|
+
async signUpWithPasskey(email, displayName) {
|
|
1576
|
+
return this.withSigningIn(
|
|
1577
|
+
async () => this.adoptWire(await passkeySignUp(this.rt, email, displayName))
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Add a passkey to the signed-in account, so the next sign-in is one tap.
|
|
1582
|
+
*
|
|
1583
|
+
* Rejects with a 403 `reauthentication_required` when the session is not
|
|
1584
|
+
* recent: a passkey outlives a password reset, so enrolling one takes more
|
|
1585
|
+
* than a valid session.
|
|
1586
|
+
*/
|
|
1587
|
+
async registerPasskey(name) {
|
|
1588
|
+
await passkeyRegister(this.rt, name);
|
|
1589
|
+
}
|
|
1590
|
+
/** Whether this browser can run a passkey ceremony at all. */
|
|
1591
|
+
get passkeysSupported() {
|
|
1592
|
+
return isPasskeySupported();
|
|
1593
|
+
}
|
|
1405
1594
|
async signInWithOAuth(params) {
|
|
1406
1595
|
const { redirect = true, ...opts } = params;
|
|
1407
1596
|
const { url } = unwrap(await this.rt.authClient.getOAuthURL(opts));
|
|
@@ -8650,7 +8839,7 @@ function defaultSessionStorage(key) {
|
|
|
8650
8839
|
}
|
|
8651
8840
|
|
|
8652
8841
|
// src/version.ts
|
|
8653
|
-
var VERSION = "7.
|
|
8842
|
+
var VERSION = "7.1.0";
|
|
8654
8843
|
|
|
8655
8844
|
// src/runtime.ts
|
|
8656
8845
|
function buildRuntime(config) {
|
|
@@ -9075,4 +9264,4 @@ export {
|
|
|
9075
9264
|
pb,
|
|
9076
9265
|
createBoundClient
|
|
9077
9266
|
};
|
|
9078
|
-
//# sourceMappingURL=chunk-
|
|
9267
|
+
//# sourceMappingURL=chunk-P6TWUWZC.js.map
|