@pidgeon-ai/cli 1.42.3 → 1.44.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.
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  COMMANDS,
4
4
  __export
5
- } from "./chunk-DHEC6LXJ.js";
5
+ } from "./chunk-FZA3INVW.js";
6
6
 
7
7
  // ../sdk/dist/index.js
8
8
  var dist_exports = {};
@@ -2043,7 +2043,7 @@ function sleep(ms, signal) {
2043
2043
  });
2044
2044
  }
2045
2045
 
2046
- // ../id/dist/chunk-JHNL23AX.js
2046
+ // ../id/dist/chunk-QDQDZSU7.js
2047
2047
  import { createHash } from "crypto";
2048
2048
  import { chmod, mkdir, readFile, readdir, writeFile } from "fs/promises";
2049
2049
  import { homedir } from "os";
@@ -2663,7 +2663,23 @@ async function siteMetadata(site, fetcher = fetch) {
2663
2663
  `${site} does not offer Sign in with Pidgeon.`
2664
2664
  );
2665
2665
  }
2666
- return { issuer: body.issuer, client_id: body.client_id, token_endpoint: site };
2666
+ const trim = (issuer) => issuer.replace(/\/$/, "");
2667
+ const listed = Array.isArray(body.issuers) ? body.issuers.filter((issuer) => typeof issuer === "string").map(trim) : [];
2668
+ return {
2669
+ issuer: body.issuer,
2670
+ issuers: [.../* @__PURE__ */ new Set([trim(body.issuer), ...listed])],
2671
+ client_id: body.client_id,
2672
+ token_endpoint: site
2673
+ };
2674
+ }
2675
+ function issuerFor(site, card) {
2676
+ try {
2677
+ const payload = JSON.parse(Buffer.from(card.split(".")[1] ?? "", "base64url").toString("utf8"));
2678
+ const iss = typeof payload?.iss === "string" ? payload.iss.replace(/\/$/, "") : null;
2679
+ if (iss && site.issuers.includes(iss)) return iss;
2680
+ } catch {
2681
+ }
2682
+ return site.issuer.replace(/\/$/, "");
2667
2683
  }
2668
2684
  async function fetchCard(agent, fetcher = fetch, postHost = (domain) => `https://post.${domain}`) {
2669
2685
  const domain = agent.split("@")[1] ?? "";
@@ -2701,12 +2717,11 @@ async function signIn(identity, input, authenticate, admit) {
2701
2717
  const site = await siteMetadata(input.site, fetcher);
2702
2718
  admit?.(site);
2703
2719
  const card = input.card ?? await fetchCard(agent, fetcher, input.postHost);
2704
- const discovery = await json(
2705
- await fetcher(`${site.issuer.replace(/\/$/, "")}/.well-known/openid-configuration`)
2706
- );
2720
+ const issuer = admit ? site.issuer.replace(/\/$/, "") : issuerFor(site, card);
2721
+ const discovery = await json(await fetcher(`${issuer}/.well-known/openid-configuration`));
2707
2722
  const tokenEndpoint = discovery.token_endpoint;
2708
2723
  if (typeof tokenEndpoint !== "string") {
2709
- throw new SignInError("pidgeon", 0, void 0, `${site.issuer} has no token endpoint.`);
2724
+ throw new SignInError("pidgeon", 0, void 0, `${issuer} has no token endpoint.`);
2710
2725
  }
2711
2726
  const exchange = form({
2712
2727
  grant_type: TOKEN_EXCHANGE,
@@ -3321,4 +3336,4 @@ export {
3321
3336
  find,
3322
3337
  run
3323
3338
  };
3324
- //# sourceMappingURL=chunk-IR4HMGBX.js.map
3339
+ //# sourceMappingURL=chunk-M4R74E7X.js.map