@getcirrus/pds 0.12.0 → 0.14.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 +31 -0
- package/dist/cli.js +404 -5
- package/dist/index.d.ts +104 -42
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +447 -33
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -221,6 +221,34 @@ Lists all registered passkeys with their names, IDs, and last used timestamps.
|
|
|
221
221
|
|
|
222
222
|
Interactively select and remove a passkey from the account.
|
|
223
223
|
|
|
224
|
+
### `pds app-password`
|
|
225
|
+
|
|
226
|
+
Manage app passwords for third-party client access.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
pds app-password create # Create a new app password
|
|
230
|
+
pds app-password list # List app passwords
|
|
231
|
+
pds app-password revoke # Revoke an app password
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
All app-password commands support:
|
|
235
|
+
|
|
236
|
+
- `--dev` – Target the local development server instead of production
|
|
237
|
+
|
|
238
|
+
#### `pds app-password create`
|
|
239
|
+
|
|
240
|
+
Creates a new app password. Prompts for a name (for example, "Graysky" or "Skeet client"), generates a secure password in `xxxx-xxxx-xxxx-xxxx` format, and displays it once. The password cannot be retrieved after creation.
|
|
241
|
+
|
|
242
|
+
App passwords grant the same access as the account password but are designed for use in third-party clients. They can be individually revoked without changing the account password.
|
|
243
|
+
|
|
244
|
+
#### `pds app-password list`
|
|
245
|
+
|
|
246
|
+
Lists all app passwords with their names and creation dates. Passwords themselves are never shown — only the names.
|
|
247
|
+
|
|
248
|
+
#### `pds app-password revoke`
|
|
249
|
+
|
|
250
|
+
Interactively select and revoke an app password. Use `-y` to skip the confirmation prompt. Sessions created with a revoked app password continue to work until the access token expires, but no new sessions can be created.
|
|
251
|
+
|
|
224
252
|
### `pds secret`
|
|
225
253
|
|
|
226
254
|
Manage individual secrets.
|
|
@@ -424,6 +452,9 @@ See [Cloudflare's data location documentation](https://developers.cloudflare.com
|
|
|
424
452
|
| `POST /xrpc/com.atproto.server.createSession` | No | Login with password, get JWT |
|
|
425
453
|
| `POST /xrpc/com.atproto.server.refreshSession` | Yes | Refresh JWT tokens |
|
|
426
454
|
| `GET /xrpc/com.atproto.server.getSession` | Yes | Get current session info |
|
|
455
|
+
| `POST /xrpc/com.atproto.server.createAppPassword` | Yes | Create an app password |
|
|
456
|
+
| `GET /xrpc/com.atproto.server.listAppPasswords` | Yes | List app passwords |
|
|
457
|
+
| `POST /xrpc/com.atproto.server.revokeAppPassword` | Yes | Revoke an app password |
|
|
427
458
|
| `POST /xrpc/com.atproto.server.deleteSession` | Yes | Logout |
|
|
428
459
|
| `GET /xrpc/com.atproto.server.getServiceAuth` | Yes | Get JWT for external services |
|
|
429
460
|
| `GET /xrpc/com.atproto.server.getAccountStatus` | Yes | Account status (active/deactivated) |
|
package/dist/cli.js
CHANGED
|
@@ -1237,6 +1237,79 @@ var PDSClient = class PDSClient {
|
|
|
1237
1237
|
});
|
|
1238
1238
|
}
|
|
1239
1239
|
/**
|
|
1240
|
+
* Create a new app password
|
|
1241
|
+
*/
|
|
1242
|
+
async createAppPassword(name) {
|
|
1243
|
+
const url = new URL("/xrpc/com.atproto.server.createAppPassword", this.baseUrl);
|
|
1244
|
+
const headers = { "Content-Type": "application/json" };
|
|
1245
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1246
|
+
const res = await fetch(url.toString(), {
|
|
1247
|
+
method: "POST",
|
|
1248
|
+
headers,
|
|
1249
|
+
body: JSON.stringify({ name })
|
|
1250
|
+
});
|
|
1251
|
+
if (!res.ok) {
|
|
1252
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1253
|
+
throw new ClientResponseError({
|
|
1254
|
+
status: res.status,
|
|
1255
|
+
headers: res.headers,
|
|
1256
|
+
data: {
|
|
1257
|
+
error: errorBody.error ?? "Unknown",
|
|
1258
|
+
message: errorBody.message
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
return res.json();
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* List all app passwords
|
|
1266
|
+
*/
|
|
1267
|
+
async listAppPasswords() {
|
|
1268
|
+
const url = new URL("/xrpc/com.atproto.server.listAppPasswords", this.baseUrl);
|
|
1269
|
+
const headers = {};
|
|
1270
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1271
|
+
const res = await fetch(url.toString(), {
|
|
1272
|
+
method: "GET",
|
|
1273
|
+
headers
|
|
1274
|
+
});
|
|
1275
|
+
if (!res.ok) {
|
|
1276
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1277
|
+
throw new ClientResponseError({
|
|
1278
|
+
status: res.status,
|
|
1279
|
+
headers: res.headers,
|
|
1280
|
+
data: {
|
|
1281
|
+
error: errorBody.error ?? "Unknown",
|
|
1282
|
+
message: errorBody.message
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
return res.json();
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Revoke an app password by name
|
|
1290
|
+
*/
|
|
1291
|
+
async revokeAppPassword(name) {
|
|
1292
|
+
const url = new URL("/xrpc/com.atproto.server.revokeAppPassword", this.baseUrl);
|
|
1293
|
+
const headers = { "Content-Type": "application/json" };
|
|
1294
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
1295
|
+
const res = await fetch(url.toString(), {
|
|
1296
|
+
method: "POST",
|
|
1297
|
+
headers,
|
|
1298
|
+
body: JSON.stringify({ name })
|
|
1299
|
+
});
|
|
1300
|
+
if (!res.ok) {
|
|
1301
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
1302
|
+
throw new ClientResponseError({
|
|
1303
|
+
status: res.status,
|
|
1304
|
+
headers: res.headers,
|
|
1305
|
+
data: {
|
|
1306
|
+
error: errorBody.error ?? "Unknown",
|
|
1307
|
+
message: errorBody.message
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1240
1313
|
* Initialize passkey registration
|
|
1241
1314
|
* Returns a URL for the user to visit on their device
|
|
1242
1315
|
*/
|
|
@@ -1539,11 +1612,11 @@ const addCommand = defineCommand({
|
|
|
1539
1612
|
/**
|
|
1540
1613
|
* Format a date as yyyy-mm-dd hh:mm
|
|
1541
1614
|
*/
|
|
1542
|
-
function formatDateTime(isoString) {
|
|
1615
|
+
function formatDateTime$1(isoString) {
|
|
1543
1616
|
const d = new Date(isoString);
|
|
1544
1617
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")} ${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
1545
1618
|
}
|
|
1546
|
-
const listCommand = defineCommand({
|
|
1619
|
+
const listCommand$1 = defineCommand({
|
|
1547
1620
|
meta: {
|
|
1548
1621
|
name: "list",
|
|
1549
1622
|
description: "List all registered passkeys"
|
|
@@ -1606,8 +1679,8 @@ const listCommand = defineCommand({
|
|
|
1606
1679
|
p.log.info("");
|
|
1607
1680
|
for (const pk of result.passkeys) {
|
|
1608
1681
|
const name = pk.name || pc.dim("(unnamed)");
|
|
1609
|
-
const created = formatDateTime(pk.createdAt);
|
|
1610
|
-
const lastUsed = pk.lastUsedAt ? formatDateTime(pk.lastUsedAt) : pc.dim("never");
|
|
1682
|
+
const created = formatDateTime$1(pk.createdAt);
|
|
1683
|
+
const lastUsed = pk.lastUsedAt ? formatDateTime$1(pk.lastUsedAt) : pc.dim("never");
|
|
1611
1684
|
const idPreview = pk.id.slice(0, 16) + "...";
|
|
1612
1685
|
console.log(` ${pc.green("●")} ${pc.bold(name)}`);
|
|
1613
1686
|
console.log(` ${pc.dim("ID:")} ${idPreview}`);
|
|
@@ -1755,11 +1828,336 @@ const passkeyCommand = defineCommand({
|
|
|
1755
1828
|
},
|
|
1756
1829
|
subCommands: {
|
|
1757
1830
|
add: addCommand,
|
|
1758
|
-
list: listCommand,
|
|
1831
|
+
list: listCommand$1,
|
|
1759
1832
|
remove: removeCommand
|
|
1760
1833
|
}
|
|
1761
1834
|
});
|
|
1762
1835
|
|
|
1836
|
+
//#endregion
|
|
1837
|
+
//#region src/cli/commands/app-password/create.ts
|
|
1838
|
+
/**
|
|
1839
|
+
* Create app password command
|
|
1840
|
+
*/
|
|
1841
|
+
const createCommand = defineCommand({
|
|
1842
|
+
meta: {
|
|
1843
|
+
name: "create",
|
|
1844
|
+
description: "Create a new app password"
|
|
1845
|
+
},
|
|
1846
|
+
args: {
|
|
1847
|
+
dev: {
|
|
1848
|
+
type: "boolean",
|
|
1849
|
+
description: "Target local development server instead of production",
|
|
1850
|
+
default: false
|
|
1851
|
+
},
|
|
1852
|
+
name: {
|
|
1853
|
+
type: "string",
|
|
1854
|
+
alias: "n",
|
|
1855
|
+
description: "Name for this app password (e.g., 'Graysky', 'Croissant')"
|
|
1856
|
+
}
|
|
1857
|
+
},
|
|
1858
|
+
async run({ args }) {
|
|
1859
|
+
const isDev = args.dev;
|
|
1860
|
+
p.intro("🔑 Create App Password");
|
|
1861
|
+
const vars = getVars();
|
|
1862
|
+
let targetUrl;
|
|
1863
|
+
try {
|
|
1864
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
1865
|
+
} catch (err) {
|
|
1866
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
1867
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
1868
|
+
process.exit(1);
|
|
1869
|
+
}
|
|
1870
|
+
const targetDomain = getDomain(targetUrl);
|
|
1871
|
+
const wranglerVars = getVars();
|
|
1872
|
+
const authToken = {
|
|
1873
|
+
...readDevVars(),
|
|
1874
|
+
...wranglerVars
|
|
1875
|
+
}.AUTH_TOKEN;
|
|
1876
|
+
if (!authToken) {
|
|
1877
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
1878
|
+
p.outro("Cancelled.");
|
|
1879
|
+
process.exit(1);
|
|
1880
|
+
}
|
|
1881
|
+
let passwordName = args.name;
|
|
1882
|
+
if (!passwordName) {
|
|
1883
|
+
const nameInput = await promptText({
|
|
1884
|
+
message: "Name for this app password:",
|
|
1885
|
+
placeholder: "Graysky, Croissant, etc."
|
|
1886
|
+
});
|
|
1887
|
+
if (!nameInput) {
|
|
1888
|
+
p.cancel("Name is required.");
|
|
1889
|
+
process.exit(1);
|
|
1890
|
+
}
|
|
1891
|
+
passwordName = nameInput;
|
|
1892
|
+
}
|
|
1893
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
1894
|
+
const spinner = p.spinner();
|
|
1895
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
1896
|
+
if (!await client.healthCheck()) {
|
|
1897
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
1898
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
1899
|
+
p.outro("Cancelled.");
|
|
1900
|
+
process.exit(1);
|
|
1901
|
+
}
|
|
1902
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
1903
|
+
spinner.start("Creating app password...");
|
|
1904
|
+
let result;
|
|
1905
|
+
try {
|
|
1906
|
+
result = await client.createAppPassword(passwordName);
|
|
1907
|
+
spinner.stop("App password created");
|
|
1908
|
+
} catch (err) {
|
|
1909
|
+
spinner.stop("Failed to create app password");
|
|
1910
|
+
let errorMessage = "Could not create app password";
|
|
1911
|
+
if (err instanceof Error) errorMessage = err.message;
|
|
1912
|
+
const errObj = err;
|
|
1913
|
+
if (errObj?.data?.message) errorMessage = errObj.data.message;
|
|
1914
|
+
else if (errObj?.data?.error) errorMessage = errObj.data.error;
|
|
1915
|
+
p.log.error(errorMessage);
|
|
1916
|
+
p.outro("Cancelled.");
|
|
1917
|
+
process.exit(1);
|
|
1918
|
+
}
|
|
1919
|
+
p.log.info("");
|
|
1920
|
+
p.log.success(`App password ${pc.bold(`"${result.name}"`)} created.`);
|
|
1921
|
+
p.log.info("");
|
|
1922
|
+
const copied = await copyToClipboard(result.password);
|
|
1923
|
+
p.note(result.password, "App Password");
|
|
1924
|
+
if (copied) p.log.info(pc.dim("Copied to clipboard."));
|
|
1925
|
+
p.log.warn("This password will not be shown again. Save it now.");
|
|
1926
|
+
const confirmed = await p.confirm({ message: "Have you saved the password?" });
|
|
1927
|
+
if (p.isCancel(confirmed)) {
|
|
1928
|
+
p.outro("Done! (password still visible above)");
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
const linesToClear = 6 + (copied ? 2 : 0) + 2 + 2;
|
|
1932
|
+
process.stdout.write(`\x1b[${linesToClear}A\x1b[0J`);
|
|
1933
|
+
p.note("xxxx-xxxx-xxxx-xxxx", "App Password (hidden)");
|
|
1934
|
+
p.log.info(pc.dim("Password hidden from terminal."));
|
|
1935
|
+
p.outro("Done!");
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region src/cli/commands/app-password/list.ts
|
|
1941
|
+
/**
|
|
1942
|
+
* List app passwords command
|
|
1943
|
+
*/
|
|
1944
|
+
/**
|
|
1945
|
+
* Format a date as yyyy-mm-dd hh:mm
|
|
1946
|
+
*/
|
|
1947
|
+
function formatDateTime(isoString) {
|
|
1948
|
+
const d = new Date(isoString);
|
|
1949
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")} ${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
1950
|
+
}
|
|
1951
|
+
const listCommand = defineCommand({
|
|
1952
|
+
meta: {
|
|
1953
|
+
name: "list",
|
|
1954
|
+
description: "List all app passwords"
|
|
1955
|
+
},
|
|
1956
|
+
args: { dev: {
|
|
1957
|
+
type: "boolean",
|
|
1958
|
+
description: "Target local development server instead of production",
|
|
1959
|
+
default: false
|
|
1960
|
+
} },
|
|
1961
|
+
async run({ args }) {
|
|
1962
|
+
const isDev = args.dev;
|
|
1963
|
+
p.intro("🔑 App Passwords");
|
|
1964
|
+
const vars = getVars();
|
|
1965
|
+
let targetUrl;
|
|
1966
|
+
try {
|
|
1967
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
1968
|
+
} catch (err) {
|
|
1969
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
1970
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
1971
|
+
process.exit(1);
|
|
1972
|
+
}
|
|
1973
|
+
const targetDomain = getDomain(targetUrl);
|
|
1974
|
+
const wranglerVars = getVars();
|
|
1975
|
+
const authToken = {
|
|
1976
|
+
...readDevVars(),
|
|
1977
|
+
...wranglerVars
|
|
1978
|
+
}.AUTH_TOKEN;
|
|
1979
|
+
if (!authToken) {
|
|
1980
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
1981
|
+
p.outro("Cancelled.");
|
|
1982
|
+
process.exit(1);
|
|
1983
|
+
}
|
|
1984
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
1985
|
+
const spinner = p.spinner();
|
|
1986
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
1987
|
+
if (!await client.healthCheck()) {
|
|
1988
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
1989
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
1990
|
+
p.outro("Cancelled.");
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
1994
|
+
spinner.start("Fetching app passwords...");
|
|
1995
|
+
let result;
|
|
1996
|
+
try {
|
|
1997
|
+
result = await client.listAppPasswords();
|
|
1998
|
+
spinner.stop("App passwords retrieved");
|
|
1999
|
+
} catch (err) {
|
|
2000
|
+
spinner.stop("Failed to fetch app passwords");
|
|
2001
|
+
p.log.error(err instanceof Error ? err.message : "Could not fetch app passwords");
|
|
2002
|
+
p.outro("Failed.");
|
|
2003
|
+
process.exit(1);
|
|
2004
|
+
}
|
|
2005
|
+
if (result.passwords.length === 0) {
|
|
2006
|
+
p.log.info("No app passwords.");
|
|
2007
|
+
p.log.info(`Run ${pc.cyan("pds app-password create")} to create one.`);
|
|
2008
|
+
} else {
|
|
2009
|
+
p.log.info("");
|
|
2010
|
+
p.log.info(`${pc.bold("App passwords:")}`);
|
|
2011
|
+
p.log.info("");
|
|
2012
|
+
for (const pw of result.passwords) {
|
|
2013
|
+
const created = formatDateTime(pw.createdAt);
|
|
2014
|
+
console.log(` ${pc.green("●")} ${pc.bold(pw.name)}`);
|
|
2015
|
+
console.log(` ${pc.dim("Created:")} ${created}`);
|
|
2016
|
+
console.log("");
|
|
2017
|
+
}
|
|
2018
|
+
p.log.info(pc.dim(`Total: ${result.passwords.length} app password(s)`));
|
|
2019
|
+
}
|
|
2020
|
+
p.outro("Done!");
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
//#endregion
|
|
2025
|
+
//#region src/cli/commands/app-password/revoke.ts
|
|
2026
|
+
/**
|
|
2027
|
+
* Revoke app password command
|
|
2028
|
+
*/
|
|
2029
|
+
const revokeCommand = defineCommand({
|
|
2030
|
+
meta: {
|
|
2031
|
+
name: "revoke",
|
|
2032
|
+
description: "Revoke an app password"
|
|
2033
|
+
},
|
|
2034
|
+
args: {
|
|
2035
|
+
dev: {
|
|
2036
|
+
type: "boolean",
|
|
2037
|
+
description: "Target local development server instead of production",
|
|
2038
|
+
default: false
|
|
2039
|
+
},
|
|
2040
|
+
name: {
|
|
2041
|
+
type: "string",
|
|
2042
|
+
alias: "n",
|
|
2043
|
+
description: "Name of the app password to revoke"
|
|
2044
|
+
},
|
|
2045
|
+
yes: {
|
|
2046
|
+
type: "boolean",
|
|
2047
|
+
alias: "y",
|
|
2048
|
+
description: "Skip confirmation",
|
|
2049
|
+
default: false
|
|
2050
|
+
}
|
|
2051
|
+
},
|
|
2052
|
+
async run({ args }) {
|
|
2053
|
+
const isDev = args.dev;
|
|
2054
|
+
const skipConfirm = args.yes;
|
|
2055
|
+
p.intro("🔑 Revoke App Password");
|
|
2056
|
+
const vars = getVars();
|
|
2057
|
+
let targetUrl;
|
|
2058
|
+
try {
|
|
2059
|
+
targetUrl = getTargetUrl(isDev, vars.PDS_HOSTNAME);
|
|
2060
|
+
} catch (err) {
|
|
2061
|
+
p.log.error(err instanceof Error ? err.message : "Configuration error");
|
|
2062
|
+
p.log.info("Run 'pds init' first to configure your PDS.");
|
|
2063
|
+
process.exit(1);
|
|
2064
|
+
}
|
|
2065
|
+
const targetDomain = getDomain(targetUrl);
|
|
2066
|
+
const wranglerVars = getVars();
|
|
2067
|
+
const authToken = {
|
|
2068
|
+
...readDevVars(),
|
|
2069
|
+
...wranglerVars
|
|
2070
|
+
}.AUTH_TOKEN;
|
|
2071
|
+
if (!authToken) {
|
|
2072
|
+
p.log.error("No AUTH_TOKEN found. Run 'pds init' first.");
|
|
2073
|
+
p.outro("Cancelled.");
|
|
2074
|
+
process.exit(1);
|
|
2075
|
+
}
|
|
2076
|
+
const client = new PDSClient(targetUrl, authToken);
|
|
2077
|
+
const spinner = p.spinner();
|
|
2078
|
+
spinner.start(`Checking PDS at ${targetDomain}...`);
|
|
2079
|
+
if (!await client.healthCheck()) {
|
|
2080
|
+
spinner.stop(`PDS not responding at ${targetDomain}`);
|
|
2081
|
+
p.log.error(`Your PDS isn't responding at ${targetUrl}`);
|
|
2082
|
+
p.outro("Cancelled.");
|
|
2083
|
+
process.exit(1);
|
|
2084
|
+
}
|
|
2085
|
+
spinner.stop(`Connected to ${targetDomain}`);
|
|
2086
|
+
let passwordName = args.name;
|
|
2087
|
+
if (!passwordName) {
|
|
2088
|
+
spinner.start("Fetching app passwords...");
|
|
2089
|
+
let result;
|
|
2090
|
+
try {
|
|
2091
|
+
result = await client.listAppPasswords();
|
|
2092
|
+
spinner.stop("App passwords retrieved");
|
|
2093
|
+
} catch (err) {
|
|
2094
|
+
spinner.stop("Failed to fetch app passwords");
|
|
2095
|
+
p.log.error(err instanceof Error ? err.message : "Could not fetch app passwords");
|
|
2096
|
+
p.outro("Failed.");
|
|
2097
|
+
process.exit(1);
|
|
2098
|
+
}
|
|
2099
|
+
if (result.passwords.length === 0) {
|
|
2100
|
+
p.log.info("No app passwords to revoke.");
|
|
2101
|
+
p.outro("Done!");
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const options = result.passwords.map((pw) => ({
|
|
2105
|
+
value: pw.name,
|
|
2106
|
+
label: pw.name,
|
|
2107
|
+
hint: `Created ${new Date(pw.createdAt).toLocaleDateString()}`
|
|
2108
|
+
}));
|
|
2109
|
+
const selected = await p.select({
|
|
2110
|
+
message: "Select app password to revoke:",
|
|
2111
|
+
options
|
|
2112
|
+
});
|
|
2113
|
+
if (p.isCancel(selected)) {
|
|
2114
|
+
p.cancel("Cancelled.");
|
|
2115
|
+
process.exit(0);
|
|
2116
|
+
}
|
|
2117
|
+
passwordName = selected;
|
|
2118
|
+
}
|
|
2119
|
+
if (!skipConfirm) {
|
|
2120
|
+
const confirm = await p.confirm({
|
|
2121
|
+
message: `Revoke app password "${passwordName}"? Any client using it will lose access.`,
|
|
2122
|
+
initialValue: false
|
|
2123
|
+
});
|
|
2124
|
+
if (p.isCancel(confirm) || !confirm) {
|
|
2125
|
+
p.cancel("Cancelled.");
|
|
2126
|
+
process.exit(0);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
spinner.start("Revoking app password...");
|
|
2130
|
+
try {
|
|
2131
|
+
await client.revokeAppPassword(passwordName);
|
|
2132
|
+
spinner.stop("App password revoked");
|
|
2133
|
+
p.log.success(`App password "${passwordName}" has been revoked.`);
|
|
2134
|
+
} catch (err) {
|
|
2135
|
+
spinner.stop("Failed to revoke app password");
|
|
2136
|
+
p.log.error(err instanceof Error ? err.message : "Could not revoke app password");
|
|
2137
|
+
p.outro("Failed.");
|
|
2138
|
+
process.exit(1);
|
|
2139
|
+
}
|
|
2140
|
+
p.outro("Done!");
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region src/cli/commands/app-password/index.ts
|
|
2146
|
+
/**
|
|
2147
|
+
* App password management commands
|
|
2148
|
+
*/
|
|
2149
|
+
const appPasswordCommand = defineCommand({
|
|
2150
|
+
meta: {
|
|
2151
|
+
name: "app-password",
|
|
2152
|
+
description: "Manage app passwords for third-party client access"
|
|
2153
|
+
},
|
|
2154
|
+
subCommands: {
|
|
2155
|
+
create: createCommand,
|
|
2156
|
+
list: listCommand,
|
|
2157
|
+
revoke: revokeCommand
|
|
2158
|
+
}
|
|
2159
|
+
});
|
|
2160
|
+
|
|
1763
2161
|
//#endregion
|
|
1764
2162
|
//#region src/cli/utils/handle-resolver.ts
|
|
1765
2163
|
/**
|
|
@@ -4648,6 +5046,7 @@ runMain(defineCommand({
|
|
|
4648
5046
|
init: initCommand,
|
|
4649
5047
|
secret: secretCommand,
|
|
4650
5048
|
passkey: passkeyCommand,
|
|
5049
|
+
"app-password": appPasswordCommand,
|
|
4651
5050
|
migrate: migrateCommand,
|
|
4652
5051
|
"migrate-token": migrateTokenCommand,
|
|
4653
5052
|
identity: identityCommand,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,77 @@ import { DurableObject } from "cloudflare:workers";
|
|
|
2
2
|
import { BlockMap, CommitData, ReadableBlockstore, Repo, RepoStorage } from "@atproto/repo";
|
|
3
3
|
import { Secp256k1Keypair } from "@atproto/crypto";
|
|
4
4
|
import { CID } from "@atproto/lex-data";
|
|
5
|
-
import { Hono } from "hono";
|
|
6
5
|
import * as _getcirrus_oauth_provider0 from "@getcirrus/oauth-provider";
|
|
7
|
-
import { AuthCodeData, ClientMetadata, OAuthStorage, PARData, TokenData } from "@getcirrus/oauth-provider";
|
|
6
|
+
import { AuthCodeData, ClientMetadata, LexiconPermissionSet, OAuthStorage, PARData, TokenData } from "@getcirrus/oauth-provider";
|
|
7
|
+
import { Hono } from "hono";
|
|
8
8
|
import * as hono_types0 from "hono/types";
|
|
9
9
|
|
|
10
|
+
//#region src/oauth-storage.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* A cached permission-set lookup. `stale` means the entry has passed its
|
|
13
|
+
* 24h soft-expiry: it is still safe to use but should be refreshed
|
|
14
|
+
* opportunistically.
|
|
15
|
+
*/
|
|
16
|
+
interface CachedPermissionSet {
|
|
17
|
+
set: LexiconPermissionSet;
|
|
18
|
+
fetchedAt: number;
|
|
19
|
+
stale: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* SQLite-backed OAuth storage for Cloudflare Durable Objects.
|
|
23
|
+
*
|
|
24
|
+
* Implements the OAuthStorage interface from @getcirrus/oauth-provider,
|
|
25
|
+
* storing OAuth data in SQLite tables within a Durable Object.
|
|
26
|
+
*/
|
|
27
|
+
declare class SqliteOAuthStorage implements OAuthStorage {
|
|
28
|
+
private sql;
|
|
29
|
+
constructor(sql: SqlStorage);
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the OAuth database schema. Should be called once on DO startup.
|
|
32
|
+
*/
|
|
33
|
+
initSchema(): void;
|
|
34
|
+
private migrateClientTable;
|
|
35
|
+
private migrateTokensTable;
|
|
36
|
+
private ensureTokenIndexes;
|
|
37
|
+
/**
|
|
38
|
+
* Clean up expired entries. Should be called periodically.
|
|
39
|
+
*/
|
|
40
|
+
cleanup(): void;
|
|
41
|
+
saveAuthCode(code: string, data: AuthCodeData): Promise<void>;
|
|
42
|
+
getAuthCode(code: string): Promise<AuthCodeData | null>;
|
|
43
|
+
deleteAuthCode(code: string): Promise<void>;
|
|
44
|
+
saveTokens(data: TokenData): Promise<void>;
|
|
45
|
+
getTokenByAccess(accessToken: string): Promise<TokenData | null>;
|
|
46
|
+
getTokenByRefresh(refreshToken: string): Promise<TokenData | null>;
|
|
47
|
+
revokeToken(accessToken: string): Promise<void>;
|
|
48
|
+
revokeAllTokens(sub: string): Promise<void>;
|
|
49
|
+
saveClient(clientId: string, metadata: ClientMetadata): Promise<void>;
|
|
50
|
+
getClient(clientId: string): Promise<ClientMetadata | null>;
|
|
51
|
+
savePAR(requestUri: string, data: PARData): Promise<void>;
|
|
52
|
+
getPAR(requestUri: string): Promise<PARData | null>;
|
|
53
|
+
deletePAR(requestUri: string): Promise<void>;
|
|
54
|
+
checkAndSaveNonce(nonce: string): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Clear all OAuth data (for testing).
|
|
57
|
+
*/
|
|
58
|
+
destroy(): void;
|
|
59
|
+
/** Soft-expiry: serve stale, but try to refresh. */
|
|
60
|
+
static readonly PERMISSION_SET_STALE_MS: number;
|
|
61
|
+
/** Hard-expiry: drop entirely. */
|
|
62
|
+
static readonly PERMISSION_SET_EXPIRY_MS: number;
|
|
63
|
+
savePermissionSet(nsid: string, set: LexiconPermissionSet, now?: number): void;
|
|
64
|
+
getPermissionSet(nsid: string): CachedPermissionSet | null;
|
|
65
|
+
/**
|
|
66
|
+
* Save a WebAuthn challenge for later verification
|
|
67
|
+
*/
|
|
68
|
+
saveWebAuthnChallenge(challenge: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Consume a WebAuthn challenge (single-use, deleted after retrieval)
|
|
71
|
+
* @returns true if challenge was valid and consumed, false if not found or expired
|
|
72
|
+
*/
|
|
73
|
+
consumeWebAuthnChallenge(challenge: string): boolean;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
10
76
|
//#region src/storage.d.ts
|
|
11
77
|
/**
|
|
12
78
|
* SQLite-backed repository storage for Cloudflare Durable Objects.
|
|
@@ -202,54 +268,28 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
202
268
|
* Clean up expired tokens.
|
|
203
269
|
*/
|
|
204
270
|
cleanupPasskeyTokens(): void;
|
|
205
|
-
}
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/oauth-storage.d.ts
|
|
208
|
-
/**
|
|
209
|
-
* SQLite-backed OAuth storage for Cloudflare Durable Objects.
|
|
210
|
-
*
|
|
211
|
-
* Implements the OAuthStorage interface from @getcirrus/oauth-provider,
|
|
212
|
-
* storing OAuth data in SQLite tables within a Durable Object.
|
|
213
|
-
*/
|
|
214
|
-
declare class SqliteOAuthStorage implements OAuthStorage {
|
|
215
|
-
private sql;
|
|
216
|
-
constructor(sql: SqlStorage);
|
|
217
|
-
/**
|
|
218
|
-
* Initialize the OAuth database schema. Should be called once on DO startup.
|
|
219
|
-
*/
|
|
220
|
-
initSchema(): void;
|
|
221
|
-
private migrateClientTable;
|
|
222
271
|
/**
|
|
223
|
-
*
|
|
272
|
+
* Save an app password (store bcrypt hash, not plaintext).
|
|
224
273
|
*/
|
|
225
|
-
|
|
226
|
-
saveAuthCode(code: string, data: AuthCodeData): Promise<void>;
|
|
227
|
-
getAuthCode(code: string): Promise<AuthCodeData | null>;
|
|
228
|
-
deleteAuthCode(code: string): Promise<void>;
|
|
229
|
-
saveTokens(data: TokenData): Promise<void>;
|
|
230
|
-
getTokenByAccess(accessToken: string): Promise<TokenData | null>;
|
|
231
|
-
getTokenByRefresh(refreshToken: string): Promise<TokenData | null>;
|
|
232
|
-
revokeToken(accessToken: string): Promise<void>;
|
|
233
|
-
revokeAllTokens(sub: string): Promise<void>;
|
|
234
|
-
saveClient(clientId: string, metadata: ClientMetadata): Promise<void>;
|
|
235
|
-
getClient(clientId: string): Promise<ClientMetadata | null>;
|
|
236
|
-
savePAR(requestUri: string, data: PARData): Promise<void>;
|
|
237
|
-
getPAR(requestUri: string): Promise<PARData | null>;
|
|
238
|
-
deletePAR(requestUri: string): Promise<void>;
|
|
239
|
-
checkAndSaveNonce(nonce: string): Promise<boolean>;
|
|
274
|
+
saveAppPassword(name: string, passwordHash: string): void;
|
|
240
275
|
/**
|
|
241
|
-
*
|
|
276
|
+
* List all app passwords (names and creation dates only — never return hashes).
|
|
242
277
|
*/
|
|
243
|
-
|
|
278
|
+
listAppPasswords(): Array<{
|
|
279
|
+
name: string;
|
|
280
|
+
createdAt: string;
|
|
281
|
+
}>;
|
|
244
282
|
/**
|
|
245
|
-
*
|
|
283
|
+
* Delete an app password by name.
|
|
246
284
|
*/
|
|
247
|
-
|
|
285
|
+
deleteAppPassword(name: string): boolean;
|
|
248
286
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @returns true if challenge was valid and consumed, false if not found or expired
|
|
287
|
+
* Get all app password hashes for verification during login.
|
|
251
288
|
*/
|
|
252
|
-
|
|
289
|
+
getAppPasswordHashes(): Array<{
|
|
290
|
+
name: string;
|
|
291
|
+
passwordHash: string;
|
|
292
|
+
}>;
|
|
253
293
|
}
|
|
254
294
|
//#endregion
|
|
255
295
|
//#region src/blobs.d.ts
|
|
@@ -676,6 +716,14 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
676
716
|
rpcDeletePAR(requestUri: string): Promise<void>;
|
|
677
717
|
/** Check and save DPoP nonce */
|
|
678
718
|
rpcCheckAndSaveNonce(nonce: string): Promise<boolean>;
|
|
719
|
+
/**
|
|
720
|
+
* Look up a cached permission-set lexicon by NSID. Returns the cached
|
|
721
|
+
* value (with `stale: true` when past its 24h soft-expiry) or null when
|
|
722
|
+
* not cached or hard-expired.
|
|
723
|
+
*/
|
|
724
|
+
rpcGetPermissionSet(nsid: string): Promise<CachedPermissionSet | null>;
|
|
725
|
+
/** Cache a fetched permission-set lexicon. */
|
|
726
|
+
rpcSavePermissionSet(nsid: string, set: _getcirrus_oauth_provider0.LexiconPermissionSet): Promise<void>;
|
|
679
727
|
/** Save a passkey credential */
|
|
680
728
|
rpcSavePasskey(credentialId: string, publicKey: Uint8Array, counter: number, name?: string): Promise<void>;
|
|
681
729
|
/** Get a passkey by credential ID */
|
|
@@ -711,6 +759,20 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
711
759
|
rpcSaveWebAuthnChallenge(challenge: string): Promise<void>;
|
|
712
760
|
/** Consume a WebAuthn challenge (single-use) */
|
|
713
761
|
rpcConsumeWebAuthnChallenge(challenge: string): Promise<boolean>;
|
|
762
|
+
/** Save an app password (bcrypt hash) */
|
|
763
|
+
rpcSaveAppPassword(name: string, passwordHash: string): Promise<void>;
|
|
764
|
+
/** List all app passwords (names and dates only) */
|
|
765
|
+
rpcListAppPasswords(): Promise<Array<{
|
|
766
|
+
name: string;
|
|
767
|
+
createdAt: string;
|
|
768
|
+
}>>;
|
|
769
|
+
/** Delete an app password by name */
|
|
770
|
+
rpcDeleteAppPassword(name: string): Promise<boolean>;
|
|
771
|
+
/** Get all app password hashes for login verification */
|
|
772
|
+
rpcGetAppPasswordHashes(): Promise<Array<{
|
|
773
|
+
name: string;
|
|
774
|
+
passwordHash: string;
|
|
775
|
+
}>>;
|
|
714
776
|
/**
|
|
715
777
|
* HTTP fetch handler for WebSocket upgrades and streaming responses.
|
|
716
778
|
* Used instead of RPC when the response can't be serialized (WebSocket)
|