@pidgeon-ai/cli 1.42.2 → 1.43.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.
@@ -2043,7 +2043,7 @@ function sleep(ms, signal) {
2043
2043
  });
2044
2044
  }
2045
2045
 
2046
- // ../id/dist/chunk-2NWPDKWJ.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] ?? "";
@@ -2695,17 +2711,17 @@ function signInWithPidgeon(identity, input) {
2695
2711
  })
2696
2712
  );
2697
2713
  }
2698
- async function signIn(identity, input, authenticate) {
2714
+ async function signIn(identity, input, authenticate, admit) {
2699
2715
  const fetcher = input.fetch ?? fetch;
2700
2716
  const agent = input.agent.trim().toLowerCase();
2701
2717
  const site = await siteMetadata(input.site, fetcher);
2718
+ admit?.(site);
2702
2719
  const card = input.card ?? await fetchCard(agent, fetcher, input.postHost);
2703
- const discovery = await json(
2704
- await fetcher(`${site.issuer.replace(/\/$/, "")}/.well-known/openid-configuration`)
2705
- );
2720
+ const issuer = admit ? site.issuer.replace(/\/$/, "") : issuerFor(site, card);
2721
+ const discovery = await json(await fetcher(`${issuer}/.well-known/openid-configuration`));
2706
2722
  const tokenEndpoint = discovery.token_endpoint;
2707
2723
  if (typeof tokenEndpoint !== "string") {
2708
- 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.`);
2709
2725
  }
2710
2726
  const exchange = form({
2711
2727
  grant_type: TOKEN_EXCHANGE,
@@ -3320,4 +3336,4 @@ export {
3320
3336
  find,
3321
3337
  run
3322
3338
  };
3323
- //# sourceMappingURL=chunk-M7BO7YR6.js.map
3339
+ //# sourceMappingURL=chunk-GUHWCV3V.js.map