bwh-auth 0.4.0 → 0.6.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 +34 -0
- package/dist/index.cjs +482 -140
- package/dist/index.d.cts +120 -2
- package/dist/index.d.ts +120 -2
- package/dist/index.js +473 -139
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -37,19 +37,27 @@ __export(index_exports, {
|
|
|
37
37
|
PasskeySection: () => PasskeySection,
|
|
38
38
|
PasswordResetRequestForm: () => PasswordResetRequestForm,
|
|
39
39
|
ResetPasswordForm: () => ResetPasswordForm,
|
|
40
|
+
ScopePicker: () => ScopePicker,
|
|
40
41
|
SignupForm: () => SignupForm,
|
|
41
42
|
TwoFactorForm: () => TwoFactorForm,
|
|
42
43
|
arrayBufferToBase64url: () => arrayBufferToBase64url,
|
|
43
44
|
authenticateWithPasskey: () => authenticateWithPasskey,
|
|
44
45
|
base64urlToArrayBuffer: () => base64urlToArrayBuffer,
|
|
46
|
+
closeImplications: () => closeImplications,
|
|
45
47
|
describeDuration: () => describeDuration,
|
|
46
48
|
getCsrfToken: () => getCsrfToken,
|
|
47
49
|
getDefaultPasskeyName: () => getDefaultPasskeyName,
|
|
50
|
+
inCatalogOrder: () => inCatalogOrder,
|
|
48
51
|
isAbortError: () => isAbortError,
|
|
49
52
|
isConditionalMediationAvailable: () => isConditionalMediationAvailable,
|
|
53
|
+
neededBy: () => neededBy,
|
|
50
54
|
registerPasskey: () => registerPasskey,
|
|
51
55
|
relyingApplicationsFrom: () => relyingApplicationsFrom,
|
|
52
|
-
|
|
56
|
+
restrictImplications: () => restrictImplications,
|
|
57
|
+
safeApplicationHref: () => safeApplicationHref,
|
|
58
|
+
sameSelection: () => sameSelection,
|
|
59
|
+
withScopes: () => withScopes,
|
|
60
|
+
withoutScopes: () => withoutScopes
|
|
53
61
|
});
|
|
54
62
|
module.exports = __toCommonJS(index_exports);
|
|
55
63
|
|
|
@@ -999,29 +1007,318 @@ function relyingApplicationsFrom(value) {
|
|
|
999
1007
|
}
|
|
1000
1008
|
|
|
1001
1009
|
// src/api-credentials-section.tsx
|
|
1010
|
+
var React6 = __toESM(require("react"), 1);
|
|
1011
|
+
|
|
1012
|
+
// src/scope-picker.tsx
|
|
1013
|
+
var import_lucide_react3 = require("lucide-react");
|
|
1002
1014
|
var React5 = __toESM(require("react"), 1);
|
|
1015
|
+
|
|
1016
|
+
// src/scope-selection.ts
|
|
1017
|
+
function closeImplications(implications) {
|
|
1018
|
+
const closed = {};
|
|
1019
|
+
for (const key of Object.keys(implications)) {
|
|
1020
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1021
|
+
const walk = (id) => {
|
|
1022
|
+
for (const needed of implications[id] ?? []) {
|
|
1023
|
+
if (needed !== key && !seen.has(needed)) {
|
|
1024
|
+
seen.add(needed);
|
|
1025
|
+
walk(needed);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
walk(key);
|
|
1030
|
+
if (seen.size > 0) {
|
|
1031
|
+
closed[key] = [...seen];
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return closed;
|
|
1035
|
+
}
|
|
1036
|
+
function restrictImplications(implications, offered) {
|
|
1037
|
+
const result = {};
|
|
1038
|
+
for (const [key, needed] of Object.entries(implications ?? {})) {
|
|
1039
|
+
if (!offered.has(key) || !Array.isArray(needed)) {
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
const kept = needed.filter((id) => offered.has(id));
|
|
1043
|
+
if (kept.length > 0) {
|
|
1044
|
+
result[key] = kept;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return result;
|
|
1048
|
+
}
|
|
1049
|
+
function inCatalogOrder(ids, catalog) {
|
|
1050
|
+
const wanted = new Set(ids);
|
|
1051
|
+
return catalog.filter((id) => wanted.has(id));
|
|
1052
|
+
}
|
|
1053
|
+
function withScopes(selected, ids, closed) {
|
|
1054
|
+
const next = new Set(selected);
|
|
1055
|
+
for (const id of ids) {
|
|
1056
|
+
next.add(id);
|
|
1057
|
+
for (const needed of closed[id] ?? []) {
|
|
1058
|
+
next.add(needed);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return next;
|
|
1062
|
+
}
|
|
1063
|
+
function withoutScopes(selected, ids, closed) {
|
|
1064
|
+
const removed = new Set(ids);
|
|
1065
|
+
const next = new Set(selected);
|
|
1066
|
+
for (const id of ids) {
|
|
1067
|
+
next.delete(id);
|
|
1068
|
+
}
|
|
1069
|
+
for (const [scope, needed] of Object.entries(closed)) {
|
|
1070
|
+
if (needed.some((id) => removed.has(id))) {
|
|
1071
|
+
next.delete(scope);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return next;
|
|
1075
|
+
}
|
|
1076
|
+
function neededBy(id, selected, closed) {
|
|
1077
|
+
return selected.filter((scope) => scope !== id && (closed[scope] ?? []).includes(id));
|
|
1078
|
+
}
|
|
1079
|
+
function sameSelection(a, b) {
|
|
1080
|
+
if (a.length !== b.length) {
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
const set = new Set(a);
|
|
1084
|
+
return b.every((id) => set.has(id));
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// src/scope-picker.tsx
|
|
1003
1088
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1004
|
-
function
|
|
1089
|
+
function resolveGroups(scopes, groups) {
|
|
1090
|
+
if (!Array.isArray(groups) || groups.length === 0) {
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
const byId = new Map(scopes.map((scope) => [scope.id, scope]));
|
|
1094
|
+
const placed = /* @__PURE__ */ new Set();
|
|
1095
|
+
const resolved = [];
|
|
1096
|
+
for (const group of groups) {
|
|
1097
|
+
const members = [];
|
|
1098
|
+
for (const id of group.scopes ?? []) {
|
|
1099
|
+
const scope = byId.get(id);
|
|
1100
|
+
if (scope && !placed.has(id)) {
|
|
1101
|
+
placed.add(id);
|
|
1102
|
+
members.push(scope);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (members.length > 0) {
|
|
1106
|
+
resolved.push({ id: group.id, label: group.label, description: group.description ?? null, sensitive: group.sensitive === true, scopes: members });
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
const rest = scopes.filter((scope) => !placed.has(scope.id));
|
|
1110
|
+
if (rest.length > 0) {
|
|
1111
|
+
resolved.push({ id: "other", label: "Other permissions", description: null, sensitive: false, scopes: rest });
|
|
1112
|
+
}
|
|
1113
|
+
return resolved.length > 0 ? resolved : null;
|
|
1114
|
+
}
|
|
1115
|
+
function DefaultBadge(props) {
|
|
1116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { ...props });
|
|
1117
|
+
}
|
|
1118
|
+
var touchRow = {
|
|
1119
|
+
display: "flex",
|
|
1120
|
+
gap: "0.625rem",
|
|
1121
|
+
alignItems: "flex-start",
|
|
1122
|
+
minHeight: 44,
|
|
1123
|
+
padding: "0.5rem 0",
|
|
1124
|
+
boxSizing: "border-box",
|
|
1125
|
+
overflowWrap: "anywhere"
|
|
1126
|
+
};
|
|
1127
|
+
var mutedStyle = { opacity: 0.7 };
|
|
1128
|
+
var gridStyle = {
|
|
1129
|
+
display: "grid",
|
|
1130
|
+
gridTemplateColumns: "repeat(auto-fill, minmax(min(100%, 300px), 1fr))",
|
|
1131
|
+
gap: "1rem",
|
|
1132
|
+
alignItems: "start"
|
|
1133
|
+
};
|
|
1134
|
+
var boxStyle = { margin: 0, minWidth: 0, border: "1px solid rgba(128, 128, 128, 0.35)", borderRadius: 10, padding: "0.25rem 1rem 0.75rem" };
|
|
1135
|
+
function ScopePicker({ idPrefix, scopes, groups, presets, implications, selected, onChange, components }) {
|
|
1136
|
+
const { Checkbox, Button, Badge, Alert } = resolveAuthComponents(components);
|
|
1137
|
+
const [open, setOpen] = React5.useState({});
|
|
1138
|
+
const catalog = React5.useMemo(() => scopes.map((scope) => scope.id), [scopes]);
|
|
1139
|
+
const closed = React5.useMemo(() => closeImplications(restrictImplications(implications, new Set(catalog))), [implications, catalog]);
|
|
1140
|
+
const layout = React5.useMemo(() => resolveGroups(scopes, groups), [scopes, groups]);
|
|
1141
|
+
const offeredPresets = React5.useMemo(
|
|
1142
|
+
() => (presets ?? []).filter((preset) => preset.scopes.length > 0 && preset.scopes.every((id) => catalog.includes(id))),
|
|
1143
|
+
[presets, catalog]
|
|
1144
|
+
);
|
|
1145
|
+
const cascades = Object.keys(closed).length > 0;
|
|
1146
|
+
const chosen = new Set(selected);
|
|
1147
|
+
const commit = (next) => onChange(inCatalogOrder(next, catalog));
|
|
1148
|
+
const toggle = (id, checked) => {
|
|
1149
|
+
if (layout === null && !cascades) {
|
|
1150
|
+
onChange(checked ? [...selected, id] : selected.filter((value) => value !== id));
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
commit(checked ? withScopes(selected, [id], closed) : withoutScopes(selected, [id], closed));
|
|
1154
|
+
};
|
|
1155
|
+
const renderRow = (scope, grouped) => {
|
|
1156
|
+
const id = `${idPrefix}-${scope.id}`;
|
|
1157
|
+
const needers = neededBy(scope.id, selected, closed);
|
|
1158
|
+
const noteId = `${id}-needed`;
|
|
1159
|
+
const row = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { htmlFor: id, style: grouped ? { ...touchRow, cursor: "pointer" } : { overflowWrap: "anywhere" }, children: [
|
|
1160
|
+
Checkbox ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Checkbox, { id, checked: chosen.has(scope.id), onCheckedChange: (checked) => toggle(scope.id, checked) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1161
|
+
"input",
|
|
1162
|
+
{
|
|
1163
|
+
id,
|
|
1164
|
+
type: "checkbox",
|
|
1165
|
+
checked: chosen.has(scope.id),
|
|
1166
|
+
"aria-describedby": needers.length > 0 ? noteId : void 0,
|
|
1167
|
+
onChange: (event) => toggle(scope.id, event.target.checked),
|
|
1168
|
+
style: grouped ? { flex: "none", width: 16, height: 16, margin: "2px 0 0" } : void 0
|
|
1169
|
+
}
|
|
1170
|
+
),
|
|
1171
|
+
" ",
|
|
1172
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
|
|
1173
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: scope.id }),
|
|
1174
|
+
" ",
|
|
1175
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: mutedStyle, children: scope.description })
|
|
1176
|
+
] })
|
|
1177
|
+
] }, scope.id);
|
|
1178
|
+
if (needers.length === 0) {
|
|
1179
|
+
return row;
|
|
1180
|
+
}
|
|
1181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { minWidth: 0 }, children: [
|
|
1182
|
+
row,
|
|
1183
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("small", { id: noteId, style: { ...mutedStyle, display: "block", paddingLeft: grouped ? 26 : 0, overflowWrap: "anywhere" }, children: [
|
|
1184
|
+
"needed by ",
|
|
1185
|
+
needers.join(", ")
|
|
1186
|
+
] })
|
|
1187
|
+
] }, scope.id);
|
|
1188
|
+
};
|
|
1189
|
+
if (layout === null) {
|
|
1190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0, minWidth: 0 }, children: [
|
|
1191
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { children: "Permissions" }),
|
|
1192
|
+
scopes.map((scope) => renderRow(scope, false))
|
|
1193
|
+
] });
|
|
1194
|
+
}
|
|
1195
|
+
const pressed = offeredPresets.find((preset) => sameSelection(selected, preset.scopes));
|
|
1196
|
+
const plain = layout.filter((group) => !group.sensitive);
|
|
1197
|
+
const sensitive = layout.filter((group) => group.sensitive);
|
|
1198
|
+
const Chip = Badge ?? DefaultBadge;
|
|
1199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "grid", gap: "1rem", minWidth: 0 }, children: [
|
|
1200
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "grid", gap: "0.25rem" }, children: [
|
|
1201
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: "Permissions" }),
|
|
1202
|
+
offeredPresets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: mutedStyle, children: "Start from a preset, then adjust any permission below. The credential stores exactly the permissions you tick." })
|
|
1203
|
+
] }),
|
|
1204
|
+
offeredPresets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "grid", gap: "0.625rem" }, children: [
|
|
1205
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { role: "group", "aria-label": "Presets", style: { display: "flex", flexWrap: "wrap", gap: "0.5rem" }, children: offeredPresets.map((preset) => {
|
|
1206
|
+
const isPressed = pressed?.id === preset.id;
|
|
1207
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1208
|
+
Button,
|
|
1209
|
+
{
|
|
1210
|
+
type: "button",
|
|
1211
|
+
variant: isPressed ? "default" : "outline",
|
|
1212
|
+
"aria-pressed": isPressed,
|
|
1213
|
+
style: { minHeight: 44, maxWidth: "100%", overflowWrap: "anywhere", whiteSpace: "normal", textAlign: "left" },
|
|
1214
|
+
onClick: () => commit(withScopes([], preset.scopes, closed)),
|
|
1215
|
+
children: preset.label
|
|
1216
|
+
},
|
|
1217
|
+
preset.id
|
|
1218
|
+
);
|
|
1219
|
+
}) }),
|
|
1220
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "aria-live": "polite", style: { margin: 0, ...mutedStyle, overflowWrap: "anywhere" }, children: pressed ? pressed.description : "Custom selection. Pick a preset to replace it, or keep adjusting below." })
|
|
1221
|
+
] }),
|
|
1222
|
+
plain.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: gridStyle, children: plain.map((group) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { style: { ...boxStyle, display: "grid", gridTemplateColumns: "minmax(0, 1fr)" }, children: [
|
|
1223
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { style: { padding: "0 0.375rem", fontWeight: 600, overflowWrap: "anywhere" }, children: group.label }),
|
|
1224
|
+
group.scopes.map((scope) => renderRow(scope, true))
|
|
1225
|
+
] }, group.id)) }),
|
|
1226
|
+
sensitive.map((group) => {
|
|
1227
|
+
const ids = group.scopes.map((scope) => scope.id);
|
|
1228
|
+
const count = ids.filter((id) => chosen.has(id)).length;
|
|
1229
|
+
const state = count === 0 ? "none" : count === ids.length ? "all" : "some";
|
|
1230
|
+
const parentId = `${idPrefix}-group-${group.id}`;
|
|
1231
|
+
const listId = `${parentId}-scopes`;
|
|
1232
|
+
const isOpen = open[group.id] === true;
|
|
1233
|
+
const warning = group.description !== null && group.description !== "" ? group.description : null;
|
|
1234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { style: { ...boxStyle, display: "grid", gap: "0.375rem", paddingBottom: "0.875rem" }, children: [
|
|
1235
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("legend", { style: { padding: "0 0.375rem", fontWeight: 600, display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
1236
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { overflowWrap: "anywhere" }, children: group.label }),
|
|
1237
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Chip, { style: { fontSize: 12, fontWeight: 500, border: "1px solid currentColor", borderRadius: 999, padding: "3px 8px", lineHeight: 1 }, children: "Sensitive" })
|
|
1238
|
+
] }),
|
|
1239
|
+
warning !== null && (() => {
|
|
1240
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1241
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react3.TriangleAlert, { "aria-hidden": "true", size: 16, style: { flex: "none", marginTop: 2 } }),
|
|
1242
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: warning })
|
|
1243
|
+
] });
|
|
1244
|
+
const style = { margin: "0.25rem 0 0", display: "flex", gap: "0.5rem", alignItems: "flex-start" };
|
|
1245
|
+
return Alert ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Alert, { style, children: content }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { ...style, color: "#b45309" }, children: content });
|
|
1246
|
+
})(),
|
|
1247
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { htmlFor: parentId, style: { ...touchRow, cursor: "pointer" }, children: [
|
|
1248
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1249
|
+
"input",
|
|
1250
|
+
{
|
|
1251
|
+
id: parentId,
|
|
1252
|
+
type: "checkbox",
|
|
1253
|
+
checked: state === "all",
|
|
1254
|
+
"aria-checked": state === "some" ? "mixed" : state === "all",
|
|
1255
|
+
ref: (element) => {
|
|
1256
|
+
if (element) {
|
|
1257
|
+
element.indeterminate = state === "some";
|
|
1258
|
+
}
|
|
1259
|
+
},
|
|
1260
|
+
onChange: () => commit(state === "all" ? withoutScopes(selected, ids, closed) : withScopes(selected, ids, closed)),
|
|
1261
|
+
style: { flex: "none", width: 16, height: 16, margin: "2px 0 0" }
|
|
1262
|
+
}
|
|
1263
|
+
),
|
|
1264
|
+
" ",
|
|
1265
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
|
|
1266
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { children: group.label }),
|
|
1267
|
+
" ",
|
|
1268
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: mutedStyle, children: state === "all" ? `All ${ids.length} ${group.label} permissions are selected.` : state === "some" ? `${count} of ${ids.length} ${group.label} permissions are selected.` : `Selects all ${ids.length} ${group.label} permissions.` })
|
|
1269
|
+
] })
|
|
1270
|
+
] }),
|
|
1271
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1272
|
+
Button,
|
|
1273
|
+
{
|
|
1274
|
+
type: "button",
|
|
1275
|
+
variant: "ghost",
|
|
1276
|
+
"aria-expanded": isOpen,
|
|
1277
|
+
"aria-controls": listId,
|
|
1278
|
+
style: { minHeight: 44, whiteSpace: "normal", textAlign: "left" },
|
|
1279
|
+
onClick: () => setOpen((current) => ({ ...current, [group.id]: !isOpen })),
|
|
1280
|
+
children: [
|
|
1281
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react3.ChevronRight, { "aria-hidden": "true", size: 16, style: { flex: "none", transition: "transform 120ms", transform: isOpen ? "rotate(90deg)" : "none" } }),
|
|
1282
|
+
isOpen ? "Hide" : "Adjust",
|
|
1283
|
+
" individual ",
|
|
1284
|
+
group.label,
|
|
1285
|
+
" permissions"
|
|
1286
|
+
]
|
|
1287
|
+
}
|
|
1288
|
+
) }),
|
|
1289
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: listId, style: { ...gridStyle, columnGap: "1.5rem", gap: "0 1.5rem", paddingLeft: "1.5rem", marginLeft: 7, borderLeft: "2px solid rgba(128, 128, 128, 0.35)" }, children: group.scopes.map((scope) => renderRow(scope, true)) })
|
|
1290
|
+
] }, group.id);
|
|
1291
|
+
}),
|
|
1292
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { borderTop: "1px solid rgba(128, 128, 128, 0.35)", paddingTop: "0.875rem", display: "grid", gap: "0.5rem" }, children: [
|
|
1293
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { margin: 0, fontWeight: 500 }, role: "status", children: selected.length === 0 ? "No permissions selected." : `This credential will request ${selected.length} ${selected.length === 1 ? "permission" : "permissions"}:` }),
|
|
1294
|
+
selected.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { margin: 0, display: "flex", flexWrap: "wrap", gap: "0.375rem" }, children: selected.map((id) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { style: { overflowWrap: "anywhere" }, children: id }, id)) })
|
|
1295
|
+
] })
|
|
1296
|
+
] });
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// src/api-credentials-section.tsx
|
|
1300
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1301
|
+
function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, request, onSuccess, onError }) {
|
|
1005
1302
|
const { Card, CardContent, CardDescription, CardHeader, CardTitle } = resolveAuthComponents(components);
|
|
1006
|
-
const [index, setIndex] =
|
|
1007
|
-
const [issued, setIssued] =
|
|
1008
|
-
const issuedKey =
|
|
1009
|
-
const addIssued =
|
|
1303
|
+
const [index, setIndex] = React6.useState(null);
|
|
1304
|
+
const [issued, setIssued] = React6.useState([]);
|
|
1305
|
+
const issuedKey = React6.useRef(0);
|
|
1306
|
+
const addIssued = React6.useCallback((credential) => {
|
|
1010
1307
|
issuedKey.current += 1;
|
|
1011
1308
|
const key = issuedKey.current;
|
|
1012
1309
|
setIssued((current) => [...current, { key, credential }]);
|
|
1013
1310
|
}, []);
|
|
1014
|
-
const [loadError, setLoadError] =
|
|
1015
|
-
const onErrorRef =
|
|
1311
|
+
const [loadError, setLoadError] = React6.useState(null);
|
|
1312
|
+
const onErrorRef = React6.useRef(onError);
|
|
1016
1313
|
onErrorRef.current = onError;
|
|
1017
|
-
const generation =
|
|
1018
|
-
const context =
|
|
1019
|
-
context.current = { indexUrl, csrfToken };
|
|
1020
|
-
const reload =
|
|
1314
|
+
const generation = React6.useRef(0);
|
|
1315
|
+
const context = React6.useRef({ indexUrl, csrfToken, request });
|
|
1316
|
+
context.current = { indexUrl, csrfToken, request };
|
|
1317
|
+
const reload = React6.useCallback(async () => {
|
|
1021
1318
|
generation.current += 1;
|
|
1022
1319
|
const mine = generation.current;
|
|
1023
|
-
const { indexUrl: url, csrfToken: token } = context.current;
|
|
1024
|
-
const result = await credentialRequest("GET", url, void 0, token);
|
|
1320
|
+
const { indexUrl: url, csrfToken: token, request: send } = context.current;
|
|
1321
|
+
const result = await credentialRequest("GET", url, void 0, token, send);
|
|
1025
1322
|
if (mine !== generation.current) {
|
|
1026
1323
|
return;
|
|
1027
1324
|
}
|
|
@@ -1033,31 +1330,31 @@ function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, on
|
|
|
1033
1330
|
onErrorRef.current?.("api-credentials", result.message);
|
|
1034
1331
|
}
|
|
1035
1332
|
}, []);
|
|
1036
|
-
|
|
1333
|
+
React6.useEffect(() => {
|
|
1037
1334
|
setIndex(null);
|
|
1038
1335
|
void reload();
|
|
1039
1336
|
}, [indexUrl, csrfToken, reload]);
|
|
1040
|
-
const removeLocally =
|
|
1337
|
+
const removeLocally = React6.useCallback((list, id) => {
|
|
1041
1338
|
setIndex(
|
|
1042
1339
|
(current) => current === null ? current : list === "tokens" ? { ...current, tokens: current.tokens.filter((token) => token.id !== id) } : { ...current, apps: current.apps.filter((app) => app.id !== id) }
|
|
1043
1340
|
);
|
|
1044
1341
|
}, []);
|
|
1045
|
-
const shared = { components, csrfToken, onError, onSuccess, removeLocally };
|
|
1046
|
-
return /* @__PURE__ */ (0,
|
|
1047
|
-
/* @__PURE__ */ (0,
|
|
1048
|
-
/* @__PURE__ */ (0,
|
|
1049
|
-
/* @__PURE__ */ (0,
|
|
1342
|
+
const shared = { components, csrfToken, request, onError, onSuccess, removeLocally };
|
|
1343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Card, { children: [
|
|
1344
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(CardHeader, { children: [
|
|
1345
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CardTitle, { children: "API access" }),
|
|
1346
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CardDescription, { children: "Connect apps that use the API. Register an OAuth app for apps that sign you in, or create an API token for apps that ask for a key. Each carries only the permissions you choose, and never more than your own access." })
|
|
1050
1347
|
] }),
|
|
1051
|
-
/* @__PURE__ */ (0,
|
|
1052
|
-
links.length > 0 && /* @__PURE__ */ (0,
|
|
1053
|
-
/* @__PURE__ */ (0,
|
|
1054
|
-
/* @__PURE__ */ (0,
|
|
1055
|
-
/* @__PURE__ */ (0,
|
|
1348
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CardContent, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "grid", gap: "1.5rem", minWidth: 0 }, children: [
|
|
1349
|
+
links.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("dl", { style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: links.map((link) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { minWidth: 0 }, children: [
|
|
1350
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("dt", { children: link.label }),
|
|
1351
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("dd", { style: { margin: 0, overflowWrap: "anywhere" }, children: [
|
|
1352
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: link.url }),
|
|
1056
1353
|
" ",
|
|
1057
|
-
/* @__PURE__ */ (0,
|
|
1354
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CopyButton, { text: link.url, label: link.label, components })
|
|
1058
1355
|
] })
|
|
1059
1356
|
] }, link.label)) }),
|
|
1060
|
-
issued.map(({ key, credential }) => /* @__PURE__ */ (0,
|
|
1357
|
+
issued.map(({ key, credential }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1061
1358
|
IssuedNotice,
|
|
1062
1359
|
{
|
|
1063
1360
|
issued: credential,
|
|
@@ -1066,29 +1363,36 @@ function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, on
|
|
|
1066
1363
|
},
|
|
1067
1364
|
key
|
|
1068
1365
|
)),
|
|
1069
|
-
loadError !== null && /* @__PURE__ */ (0,
|
|
1070
|
-
index !== null && /* @__PURE__ */ (0,
|
|
1071
|
-
(index.issue_token_href === null || index.register_app_href === null) && /* @__PURE__ */ (0,
|
|
1072
|
-
/* @__PURE__ */ (0,
|
|
1073
|
-
/* @__PURE__ */ (0,
|
|
1366
|
+
loadError !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", children: loadError }),
|
|
1367
|
+
index !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1368
|
+
(index.issue_token_href === null || index.register_app_href === null) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "status", children: "Creating new credentials is unavailable right now. You can still revoke existing ones." }),
|
|
1369
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TokenSection, { index, ...shared, onIssued: addIssued, reload }),
|
|
1370
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AppSection, { index, ...shared, onIssued: addIssued, reload })
|
|
1074
1371
|
] })
|
|
1075
1372
|
] }) })
|
|
1076
1373
|
] });
|
|
1077
1374
|
}
|
|
1078
|
-
function TokenSection({ index, components, csrfToken, onIssued, reload, onSuccess, onError, removeLocally }) {
|
|
1079
|
-
const { Button, Input, Label } = resolveAuthComponents(components);
|
|
1080
|
-
const [name, setName] =
|
|
1081
|
-
const [scopes, setScopes] =
|
|
1082
|
-
const [lifetime, setLifetime] =
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1375
|
+
function TokenSection({ index, components, csrfToken, request, onIssued, reload, onSuccess, onError, removeLocally }) {
|
|
1376
|
+
const { Button, Input, Label, RadioGroup } = resolveAuthComponents(components);
|
|
1377
|
+
const [name, setName] = React6.useState("");
|
|
1378
|
+
const [scopes, setScopes] = React6.useState([]);
|
|
1379
|
+
const [lifetime, setLifetime] = React6.useState(index.token_lifetimes[0] ?? "");
|
|
1380
|
+
const tokenScopes = React6.useMemo(
|
|
1381
|
+
() => [...index.token_scopes ?? index.scopes, ...index.token_connection_scopes ?? []],
|
|
1382
|
+
[index.token_scopes, index.scopes, index.token_connection_scopes]
|
|
1383
|
+
);
|
|
1384
|
+
const connectionIds = new Set((index.token_connection_scopes ?? []).map((scope) => scope.id));
|
|
1385
|
+
const lifetimes = index.connection_token_lifetimes && index.connection_token_lifetimes.length > 0 && scopes.some((id) => connectionIds.has(id)) ? index.connection_token_lifetimes : index.token_lifetimes;
|
|
1386
|
+
const effectiveLifetime = lifetimes.includes(lifetime) ? lifetime : lifetimes[0] ?? "";
|
|
1387
|
+
const [busy, setBusy] = React6.useState(false);
|
|
1388
|
+
const [error, setError] = React6.useState(null);
|
|
1085
1389
|
async function create(event) {
|
|
1086
1390
|
event.preventDefault();
|
|
1087
1391
|
if (index.issue_token_href === null) {
|
|
1088
1392
|
return;
|
|
1089
1393
|
}
|
|
1090
1394
|
setBusy(true);
|
|
1091
|
-
const result = await credentialRequest("POST", index.issue_token_href, { name, scopes, lifetime }, csrfToken);
|
|
1395
|
+
const result = await credentialRequest("POST", index.issue_token_href, { name, scopes, lifetime: effectiveLifetime }, csrfToken, request);
|
|
1092
1396
|
setBusy(false);
|
|
1093
1397
|
if (!result.ok) {
|
|
1094
1398
|
setError(result.message);
|
|
@@ -1102,13 +1406,13 @@ function TokenSection({ index, components, csrfToken, onIssued, reload, onSucces
|
|
|
1102
1406
|
onSuccess?.("API token created.");
|
|
1103
1407
|
await reload();
|
|
1104
1408
|
}
|
|
1105
|
-
const [pending, setPending] =
|
|
1409
|
+
const [pending, setPending] = React6.useState([]);
|
|
1106
1410
|
async function revoke(token) {
|
|
1107
1411
|
if (pending.includes(token.id)) {
|
|
1108
1412
|
return;
|
|
1109
1413
|
}
|
|
1110
1414
|
setPending((current) => [...current, token.id]);
|
|
1111
|
-
const result = await credentialRequest("DELETE", token.revoke_href, void 0, csrfToken);
|
|
1415
|
+
const result = await credentialRequest("DELETE", token.revoke_href, void 0, csrfToken, request);
|
|
1112
1416
|
if (!result.ok) {
|
|
1113
1417
|
setPending((current) => current.filter((id) => id !== token.id));
|
|
1114
1418
|
setError(result.message);
|
|
@@ -1121,46 +1425,67 @@ function TokenSection({ index, components, csrfToken, onIssued, reload, onSucces
|
|
|
1121
1425
|
await reload();
|
|
1122
1426
|
setPending((current) => current.filter((id) => id !== token.id));
|
|
1123
1427
|
}
|
|
1124
|
-
return /* @__PURE__ */ (0,
|
|
1125
|
-
/* @__PURE__ */ (0,
|
|
1126
|
-
index.issue_token_href !== null && /* @__PURE__ */ (0,
|
|
1127
|
-
/* @__PURE__ */ (0,
|
|
1128
|
-
/* @__PURE__ */ (0,
|
|
1129
|
-
/* @__PURE__ */ (0,
|
|
1428
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
|
|
1429
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: "API tokens" }),
|
|
1430
|
+
index.issue_token_href !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { onSubmit: create, style: { display: "grid", gap: "0.75rem" }, children: [
|
|
1431
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "grid", gap: "0.25rem" }, children: [
|
|
1432
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { htmlFor: "api-token-name", children: "Token name" }),
|
|
1433
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { id: "api-token-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
|
|
1130
1434
|
] }),
|
|
1131
|
-
/* @__PURE__ */ (0,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1435
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1436
|
+
ScopePicker,
|
|
1437
|
+
{
|
|
1438
|
+
idPrefix: "api-token-scope",
|
|
1439
|
+
scopes: tokenScopes,
|
|
1440
|
+
groups: index.token_scope_groups ?? index.scope_groups,
|
|
1441
|
+
presets: index.token_scope_presets ?? index.scope_presets,
|
|
1442
|
+
implications: index.token_scope_implications ?? index.scope_implications,
|
|
1443
|
+
selected: scopes,
|
|
1444
|
+
onChange: setScopes,
|
|
1445
|
+
components
|
|
1446
|
+
}
|
|
1447
|
+
),
|
|
1448
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
|
|
1449
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { children: "Expires after" }),
|
|
1450
|
+
RadioGroup ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1451
|
+
RadioGroup,
|
|
1452
|
+
{
|
|
1453
|
+
name: "api-token-lifetime",
|
|
1454
|
+
value: effectiveLifetime,
|
|
1455
|
+
onValueChange: setLifetime,
|
|
1456
|
+
options: lifetimes.map((spec) => ({ value: spec, label: describeDuration(spec) }))
|
|
1457
|
+
}
|
|
1458
|
+
) : lifetimes.map((spec) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
|
|
1459
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "radio", name: "api-token-lifetime", checked: effectiveLifetime === spec, onChange: () => setLifetime(spec) }),
|
|
1136
1460
|
" ",
|
|
1137
1461
|
describeDuration(spec)
|
|
1138
1462
|
] }, spec))
|
|
1139
1463
|
] }),
|
|
1140
|
-
/* @__PURE__ */ (0,
|
|
1464
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "submit", disabled: busy || name.trim() === "" || scopes.length === 0 || effectiveLifetime === "", children: "Create API token" }) })
|
|
1141
1465
|
] }),
|
|
1142
|
-
error !== null && /* @__PURE__ */ (0,
|
|
1143
|
-
/* @__PURE__ */ (0,
|
|
1144
|
-
/* @__PURE__ */ (0,
|
|
1466
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", children: error }),
|
|
1467
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.tokens.map((token) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
|
|
1468
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: token.name }),
|
|
1145
1469
|
" \xB7 ",
|
|
1146
1470
|
token.scopes.join(", "),
|
|
1147
|
-
token.
|
|
1471
|
+
token.connection === true && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: " \xB7 MCP connection" }),
|
|
1472
|
+
token.expires_at !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1148
1473
|
" \xB7 expires ",
|
|
1149
1474
|
new Date(token.expires_at).toLocaleString()
|
|
1150
1475
|
] }),
|
|
1151
1476
|
" ",
|
|
1152
|
-
/* @__PURE__ */ (0,
|
|
1477
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "button", disabled: pending.includes(token.id), onClick: () => void revoke(token), children: "Revoke" })
|
|
1153
1478
|
] }, token.id)) })
|
|
1154
1479
|
] });
|
|
1155
1480
|
}
|
|
1156
|
-
function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess, onError, removeLocally }) {
|
|
1157
|
-
const { Button, Input, Label } = resolveAuthComponents(components);
|
|
1158
|
-
const [name, setName] =
|
|
1159
|
-
const [redirects, setRedirects] =
|
|
1160
|
-
const [confidential, setConfidential] =
|
|
1161
|
-
const [scopes, setScopes] =
|
|
1162
|
-
const [busy, setBusy] =
|
|
1163
|
-
const [error, setError] =
|
|
1481
|
+
function AppSection({ index, components, csrfToken, request, onIssued, reload, onSuccess, onError, removeLocally }) {
|
|
1482
|
+
const { Button, Input, Label, Textarea, RadioGroup } = resolveAuthComponents(components);
|
|
1483
|
+
const [name, setName] = React6.useState("");
|
|
1484
|
+
const [redirects, setRedirects] = React6.useState("");
|
|
1485
|
+
const [confidential, setConfidential] = React6.useState(true);
|
|
1486
|
+
const [scopes, setScopes] = React6.useState([]);
|
|
1487
|
+
const [busy, setBusy] = React6.useState(false);
|
|
1488
|
+
const [error, setError] = React6.useState(null);
|
|
1164
1489
|
const redirectUris = redirects.split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
1165
1490
|
async function register(event) {
|
|
1166
1491
|
event.preventDefault();
|
|
@@ -1172,7 +1497,8 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
|
|
|
1172
1497
|
"POST",
|
|
1173
1498
|
index.register_app_href,
|
|
1174
1499
|
{ name, redirect_uris: redirectUris, confidential, scopes },
|
|
1175
|
-
csrfToken
|
|
1500
|
+
csrfToken,
|
|
1501
|
+
request
|
|
1176
1502
|
);
|
|
1177
1503
|
setBusy(false);
|
|
1178
1504
|
if (!result.ok) {
|
|
@@ -1188,13 +1514,13 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
|
|
|
1188
1514
|
onSuccess?.("OAuth app registered.");
|
|
1189
1515
|
await reload();
|
|
1190
1516
|
}
|
|
1191
|
-
const [pending, setPending] =
|
|
1517
|
+
const [pending, setPending] = React6.useState([]);
|
|
1192
1518
|
async function remove(app) {
|
|
1193
1519
|
if (pending.includes(app.id)) {
|
|
1194
1520
|
return;
|
|
1195
1521
|
}
|
|
1196
1522
|
setPending((current) => [...current, app.id]);
|
|
1197
|
-
const result = await credentialRequest("DELETE", app.delete_href, void 0, csrfToken);
|
|
1523
|
+
const result = await credentialRequest("DELETE", app.delete_href, void 0, csrfToken, request);
|
|
1198
1524
|
if (!result.ok) {
|
|
1199
1525
|
setPending((current) => current.filter((id) => id !== app.id));
|
|
1200
1526
|
setError(result.message);
|
|
@@ -1207,76 +1533,73 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
|
|
|
1207
1533
|
await reload();
|
|
1208
1534
|
setPending((current) => current.filter((id) => id !== app.id));
|
|
1209
1535
|
}
|
|
1210
|
-
return /* @__PURE__ */ (0,
|
|
1211
|
-
/* @__PURE__ */ (0,
|
|
1212
|
-
index.register_app_href !== null && /* @__PURE__ */ (0,
|
|
1213
|
-
/* @__PURE__ */ (0,
|
|
1214
|
-
/* @__PURE__ */ (0,
|
|
1215
|
-
/* @__PURE__ */ (0,
|
|
1536
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
|
|
1537
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: "OAuth apps" }),
|
|
1538
|
+
index.register_app_href !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { onSubmit: register, style: { display: "grid", gap: "0.75rem" }, children: [
|
|
1539
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "grid", gap: "0.25rem" }, children: [
|
|
1540
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { htmlFor: "oauth-app-name", children: "App name" }),
|
|
1541
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Input, { id: "oauth-app-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
|
|
1216
1542
|
] }),
|
|
1217
|
-
/* @__PURE__ */ (0,
|
|
1218
|
-
/* @__PURE__ */ (0,
|
|
1219
|
-
/* @__PURE__ */ (0,
|
|
1543
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "grid", gap: "0.25rem" }, children: [
|
|
1544
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { htmlFor: "oauth-app-redirects", children: "Redirect URIs (one per line)" }),
|
|
1545
|
+
Textarea ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Textarea, { id: "oauth-app-redirects", rows: 3, value: redirects, onChange: (event) => setRedirects(event.target.value) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("textarea", { id: "oauth-app-redirects", rows: 3, value: redirects, onChange: (event) => setRedirects(event.target.value) })
|
|
1220
1546
|
] }),
|
|
1221
|
-
/* @__PURE__ */ (0,
|
|
1222
|
-
/* @__PURE__ */ (0,
|
|
1223
|
-
/* @__PURE__ */ (0,
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1547
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
|
|
1548
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { children: "Client type" }),
|
|
1549
|
+
RadioGroup ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1550
|
+
RadioGroup,
|
|
1551
|
+
{
|
|
1552
|
+
name: "oauth-app-type",
|
|
1553
|
+
value: confidential ? "confidential" : "public",
|
|
1554
|
+
onValueChange: (value) => setConfidential(value === "confidential"),
|
|
1555
|
+
options: [
|
|
1556
|
+
{ value: "confidential", label: "Confidential: the app keeps a client secret on its server" },
|
|
1557
|
+
{ value: "public", label: "Public: no secret, PKCE only" }
|
|
1558
|
+
]
|
|
1559
|
+
}
|
|
1560
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1561
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
|
|
1562
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "radio", name: "oauth-app-type", checked: confidential, onChange: () => setConfidential(true) }),
|
|
1563
|
+
" Confidential: the app keeps a client secret on its server"
|
|
1564
|
+
] }),
|
|
1565
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
|
|
1566
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "radio", name: "oauth-app-type", checked: !confidential, onChange: () => setConfidential(false) }),
|
|
1567
|
+
" Public: no secret, PKCE only"
|
|
1568
|
+
] })
|
|
1230
1569
|
] })
|
|
1231
1570
|
] }),
|
|
1232
|
-
/* @__PURE__ */ (0,
|
|
1233
|
-
|
|
1571
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1572
|
+
ScopePicker,
|
|
1573
|
+
{
|
|
1574
|
+
idPrefix: "oauth-app-scope",
|
|
1575
|
+
scopes: index.scopes,
|
|
1576
|
+
groups: index.scope_groups,
|
|
1577
|
+
presets: index.scope_presets,
|
|
1578
|
+
implications: index.scope_implications,
|
|
1579
|
+
selected: scopes,
|
|
1580
|
+
onChange: setScopes,
|
|
1581
|
+
components
|
|
1582
|
+
}
|
|
1583
|
+
),
|
|
1584
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "submit", disabled: busy || name.trim() === "" || redirectUris.length === 0 || scopes.length === 0, children: "Register OAuth app" }) })
|
|
1234
1585
|
] }),
|
|
1235
|
-
error !== null && /* @__PURE__ */ (0,
|
|
1236
|
-
/* @__PURE__ */ (0,
|
|
1237
|
-
/* @__PURE__ */ (0,
|
|
1586
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", children: error }),
|
|
1587
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.apps.map((app) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
|
|
1588
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: app.name }),
|
|
1238
1589
|
" \xB7 client ID ",
|
|
1239
|
-
/* @__PURE__ */ (0,
|
|
1590
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: app.id }),
|
|
1240
1591
|
" \xB7 ",
|
|
1241
1592
|
app.confidential ? "confidential" : "public",
|
|
1242
|
-
/* @__PURE__ */ (0,
|
|
1593
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
|
|
1243
1594
|
app.redirect_uris.join(", "),
|
|
1244
|
-
/* @__PURE__ */ (0,
|
|
1595
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
|
|
1245
1596
|
"May request: ",
|
|
1246
1597
|
app.scopes.join(", "),
|
|
1247
1598
|
" ",
|
|
1248
|
-
/* @__PURE__ */ (0,
|
|
1599
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "button", disabled: pending.includes(app.id), onClick: () => void remove(app), children: "Delete" })
|
|
1249
1600
|
] }, app.id)) })
|
|
1250
1601
|
] });
|
|
1251
1602
|
}
|
|
1252
|
-
function ScopePicker({
|
|
1253
|
-
idPrefix,
|
|
1254
|
-
scopes,
|
|
1255
|
-
selected,
|
|
1256
|
-
onChange
|
|
1257
|
-
}) {
|
|
1258
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0, minWidth: 0 }, children: [
|
|
1259
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("legend", { children: "Permissions" }),
|
|
1260
|
-
scopes.map((scope) => {
|
|
1261
|
-
const id = `${idPrefix}-${scope.id}`;
|
|
1262
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { htmlFor: id, style: { overflowWrap: "anywhere" }, children: [
|
|
1263
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1264
|
-
"input",
|
|
1265
|
-
{
|
|
1266
|
-
id,
|
|
1267
|
-
type: "checkbox",
|
|
1268
|
-
checked: selected.includes(scope.id),
|
|
1269
|
-
onChange: (event) => onChange(event.target.checked ? [...selected, scope.id] : selected.filter((value) => value !== scope.id))
|
|
1270
|
-
}
|
|
1271
|
-
),
|
|
1272
|
-
" ",
|
|
1273
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: scope.id }),
|
|
1274
|
-
" ",
|
|
1275
|
-
scope.description
|
|
1276
|
-
] }, scope.id);
|
|
1277
|
-
})
|
|
1278
|
-
] });
|
|
1279
|
-
}
|
|
1280
1603
|
function IssuedNotice({
|
|
1281
1604
|
issued,
|
|
1282
1605
|
components,
|
|
@@ -1287,26 +1610,26 @@ function IssuedNotice({
|
|
|
1287
1610
|
{ label: "Client ID", url: issued.client_id },
|
|
1288
1611
|
...issued.client_secret !== null ? [{ label: "Client secret", url: issued.client_secret }] : []
|
|
1289
1612
|
];
|
|
1290
|
-
return /* @__PURE__ */ (0,
|
|
1291
|
-
/* @__PURE__ */ (0,
|
|
1613
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { role: "status", style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: [
|
|
1614
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { style: { overflowWrap: "anywhere" }, children: [
|
|
1292
1615
|
issued.kind === "token" ? `API token \u201C${issued.name}\u201D created.` : `OAuth app \u201C${issued.name}\u201D registered.`,
|
|
1293
1616
|
" Copy it now: it will not be shown again."
|
|
1294
1617
|
] }),
|
|
1295
|
-
values.map((value) => /* @__PURE__ */ (0,
|
|
1618
|
+
values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
|
|
1296
1619
|
value.label,
|
|
1297
1620
|
": ",
|
|
1298
|
-
/* @__PURE__ */ (0,
|
|
1621
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { children: value.url }),
|
|
1299
1622
|
" ",
|
|
1300
|
-
/* @__PURE__ */ (0,
|
|
1623
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CopyButton, { text: value.url, label: value.label, components })
|
|
1301
1624
|
] }, value.label)),
|
|
1302
|
-
/* @__PURE__ */ (0,
|
|
1625
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Button, { type: "button", onClick: onDismiss, children: "Done" }) })
|
|
1303
1626
|
] });
|
|
1304
1627
|
}
|
|
1305
1628
|
function CopyButton({ text, label, components }) {
|
|
1306
1629
|
const { Button } = resolveAuthComponents(components);
|
|
1307
|
-
const [state, setState] =
|
|
1308
|
-
return /* @__PURE__ */ (0,
|
|
1309
|
-
/* @__PURE__ */ (0,
|
|
1630
|
+
const [state, setState] = React6.useState("idle");
|
|
1631
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1632
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1310
1633
|
Button,
|
|
1311
1634
|
{
|
|
1312
1635
|
type: "button",
|
|
@@ -1326,7 +1649,7 @@ function CopyButton({ text, label, components }) {
|
|
|
1326
1649
|
children: state === "copied" ? "Copied" : "Copy"
|
|
1327
1650
|
}
|
|
1328
1651
|
),
|
|
1329
|
-
state === "failed" && /* @__PURE__ */ (0,
|
|
1652
|
+
state === "failed" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { role: "status", children: " Copying is unavailable here; select the text and copy it manually." })
|
|
1330
1653
|
] });
|
|
1331
1654
|
}
|
|
1332
1655
|
function describeDuration(spec) {
|
|
@@ -1338,7 +1661,16 @@ function describeDuration(spec) {
|
|
|
1338
1661
|
const parts = match.slice(1).map((value, position) => value ? `${Number(value)} ${units[position]}${Number(value) === 1 ? "" : "s"}` : null).filter((part) => part !== null);
|
|
1339
1662
|
return parts.length > 0 ? parts.join(" ") : spec;
|
|
1340
1663
|
}
|
|
1341
|
-
async function credentialRequest(method, url, body, csrfToken) {
|
|
1664
|
+
async function credentialRequest(method, url, body, csrfToken, request) {
|
|
1665
|
+
if (request !== void 0) {
|
|
1666
|
+
let result;
|
|
1667
|
+
try {
|
|
1668
|
+
result = await request(method, url, body);
|
|
1669
|
+
} catch {
|
|
1670
|
+
return { ok: false, status: 0, message: "The server could not be reached. Check the connection and try again." };
|
|
1671
|
+
}
|
|
1672
|
+
return result.ok ? { ok: true, status: result.status, data: unwrapData(result.payload) } : result;
|
|
1673
|
+
}
|
|
1342
1674
|
let response;
|
|
1343
1675
|
try {
|
|
1344
1676
|
response = await fetch(url, {
|
|
@@ -1356,11 +1688,13 @@ async function credentialRequest(method, url, body, csrfToken) {
|
|
|
1356
1688
|
}
|
|
1357
1689
|
const payload = await response.json().catch(() => null);
|
|
1358
1690
|
if (response.ok) {
|
|
1359
|
-
|
|
1360
|
-
return { ok: true, status: response.status, data };
|
|
1691
|
+
return { ok: true, status: response.status, data: unwrapData(payload) };
|
|
1361
1692
|
}
|
|
1362
1693
|
return { ok: false, status: response.status, message: refusalMessage(response.status, payload) };
|
|
1363
1694
|
}
|
|
1695
|
+
function unwrapData(payload) {
|
|
1696
|
+
return typeof payload === "object" && payload !== null && "data" in payload ? payload.data : payload;
|
|
1697
|
+
}
|
|
1364
1698
|
function refusalMessage(status, payload) {
|
|
1365
1699
|
if (status === 401 || status === 419) {
|
|
1366
1700
|
return "Your session has expired. Reload the page and sign in again.";
|
|
@@ -1395,17 +1729,25 @@ function refusalMessage(status, payload) {
|
|
|
1395
1729
|
PasskeySection,
|
|
1396
1730
|
PasswordResetRequestForm,
|
|
1397
1731
|
ResetPasswordForm,
|
|
1732
|
+
ScopePicker,
|
|
1398
1733
|
SignupForm,
|
|
1399
1734
|
TwoFactorForm,
|
|
1400
1735
|
arrayBufferToBase64url,
|
|
1401
1736
|
authenticateWithPasskey,
|
|
1402
1737
|
base64urlToArrayBuffer,
|
|
1738
|
+
closeImplications,
|
|
1403
1739
|
describeDuration,
|
|
1404
1740
|
getCsrfToken,
|
|
1405
1741
|
getDefaultPasskeyName,
|
|
1742
|
+
inCatalogOrder,
|
|
1406
1743
|
isAbortError,
|
|
1407
1744
|
isConditionalMediationAvailable,
|
|
1745
|
+
neededBy,
|
|
1408
1746
|
registerPasskey,
|
|
1409
1747
|
relyingApplicationsFrom,
|
|
1410
|
-
|
|
1748
|
+
restrictImplications,
|
|
1749
|
+
safeApplicationHref,
|
|
1750
|
+
sameSelection,
|
|
1751
|
+
withScopes,
|
|
1752
|
+
withoutScopes
|
|
1411
1753
|
});
|