espennilsen/pi / extensions/pi-a2a
pi-a2a
Flaggedoutbound-auth.ts
View on GitHub/** Build secret-bearing outbound auth only after peer mode selection succeeds. */
import type { AuthSelection, LocalAuthOverride, PeerAuthMetadata } from "./auth-types.ts";
import type { TokenProvider } from "./token-provider.ts";
export interface OutboundAuthContext {
headers: { Authorization: string };
mode: NonNullable<AuthSelection["selectedAuthMode"]>;
transport: { kind: "default" } | { kind: "mtls"; certPath: string; keyPath: string; caPath?: string };
}
export interface BuildOutboundAuthInput {
peer: PeerAuthMetadata;
selection: AuthSelection;
provider: TokenProvider;
localAuth?: LocalAuthOverride;
}
/**
* Produces headers and an intentionally transport-agnostic mTLS descriptor.
* Callers must create the actual HTTPS transport from this descriptor later.
*/
export async function buildOutboundAuthContext(input: BuildOutboundAuthInput): Promise<OutboundAuthContext> {
const mode = input.selection.selectedAuthMode;
if (!mode || input.selection.denial) throw new Error("No mutually supported authentication mode");
if (mode === "oauth2+mtls") {
// The SDK client cannot install a certificate-bearing HTTPS transport. Reject
// before consulting the provider, so client credentials are never acquired.
throw new Error("OAuth 2.0 + mTLS is unavailable until outbound mTLS transport is installed");
}
const token = await input.provider.getAccessToken(input.peer, input.selection);
if (token.mode !== mode) throw new Error("Token provider returned a token for the wrong authentication mode");
return { headers: { Authorization: `Bearer ${token.value}` }, mode, transport: { kind: "default" } };
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |