serviceToken

tcmts.cli.test.e2e.contributions.serviceToken · #6nss62he · function · runs anywhere

A service-auth token signed for account to the server at url, as its PDS signs one (its app password's session).

import { serviceDid } from "#codebase/tcmts/atproto";
import type { FakeAccount, FakeNetwork } from "#codebase/tcmts/atproto/testing";
import { SERVE_LXM } from "#codebase/tcmts/cli/atproto";

export async function serviceToken(
  net: FakeNetwork,
  account: FakeAccount,
  url: string,
): Promise<string> {
  const q = new URLSearchParams({
    aud: serviceDid(url),
    lxm: SERVE_LXM,
    exp: String(Math.floor(Date.now() / 1000) + 300),
  });
  const res = await fetch(`${net.url}/xrpc/com.atproto.server.getServiceAuth?${q}`, {
    headers: { authorization: `Bearer acc-${account.did}` },
  });
  return ((await res.json()) as { token: string }).token;
}

uses

used by