Skip to content

espennilsen/pi / extensions/pi-a2a

pi-a2a

Flagged

FileKindSize
AGENTS.mdmarkdown12.0 KB
CHANGELOG.mdmarkdown1.3 KB
README.mdmarkdown11.0 KB
SKILL.mdskill md9.7 KB
agent-card-auth.test.tsscript1.7 KB
agent-card.tsscript6.1 KB
agent-executor.tsscript38.7 KB
auth-integration.test.tsscript4.6 KB
auth-selector.test.tsscript4.0 KB
auth-selector.tsscript2.6 KB
auth-types.tsscript3.7 KB
client.test.tsscript3.1 KB
client.tsscript14.9 KB
config-auth.test.tsscript4.0 KB
config.tsscript9.1 KB
cost.test.tsscript1.8 KB
hub.test.tsscript6.2 KB
hub.tsscript39.5 KB
inbound-auth.test.tsscript2.6 KB
inbound-auth.tsscript4.4 KB
index.tsscript136.5 KB
logger.tsscript1.5 KB
long-running-task-store.tsscript6.3 KB
outbound-auth.test.tsscript1.5 KB
outbound-auth.tsscript1.6 KB
package-lock.jsonmanifest149.9 KB
package.jsonmanifest1.5 KB
peer-metadata.test.tsscript3.7 KB
peer-metadata.tsscript4.6 KB
port-finder.tsscript742 B
server.tsscript12.6 KB
static-agents.tsscript5.8 KB
supervisor.test.tsscript6.1 KB
supervisor.tsscript8.4 KB
task-store.tsscript12.5 KB
token-provider.test.tsscript5.3 KB
token-provider.tsscript7.7 KB
tool-telemetry.test.tsscript2.8 KB
tool-telemetry.tsscript1.7 KB
tsconfig.jsonconfig274 B
types.tsscript11.3 KB

token-provider.test.ts

View on GitHub
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import type { AuthSelection, PeerAuthMetadata } from "./auth-types.ts";
import { LegacyApiKeyProvider, OAuthClientCredentialsProvider } from "./token-provider.ts";

const peer: PeerAuthMetadata = {
	agentId: "peer-1", endpoint: "https://peer.example", source: "hub",
	supportedAuthModes: ["oauth2"], authorizationServer: "https://issuer.example/token", resource: "https://peer.example/a2a",
};
const oauthSelection: AuthSelection = { selectedAuthMode: "oauth2", source: "hub", denial: null };

describe("token providers", () => {
	it("returns the configured key from the legacy provider", async () => {
		const provider = new LegacyApiKeyProvider("legacy-secret");
		assert.deepEqual(await provider.getAccessToken({ ...peer, supportedAuthModes: ["legacy-api-key"] }, { ...oauthSelection, selectedAuthMode: "legacy-api-key" }), {
			value: "legacy-secret", tokenType: "Bearer", mode: "legacy-api-key",
		});
	});

	it("uses the peer authorization-server endpoint, requests resource/audience, and caches OAuth tokens", async () => {
		const requests: Array<{ url: string; body: URLSearchParams }> = [];
		const provider = new OAuthClientCredentialsProvider({ clientId: "client-id", clientSecret: "client-secret", trustedTokenEndpointOrigins: ["https://issuer.example"] }, async (url, init) => {
			requests.push({ url: String(url), body: new URLSearchParams(String(init?.body)) });
			return new Response(JSON.stringify({ access_token: "oauth-secret", token_type: "Bearer", expires_in: 3600 }), { status: 200 });
		});
		const first = await provider.getAccessToken(peer, oauthSelection);
		const second = await provider.getAccessToken(peer, oauthSelection);
		assert.equal(first.value, "oauth-secret");
		assert.equal(second.value, "oauth-secret");
		assert.equal(requests.length, 1);
		assert.equal(requests[0].url, "https://issuer.example/token");
		assert.equal(requests[0].body.get("grant_type"), "client_credentials");
		assert.equal(requests[0].body.get("resource"), "https://peer.example/a2a");
		assert.equal(requests[0].body.get("audience"), "https://peer.example/a2a");
		provider.invalidate(peer, oauthSelection);
		await provider.getAccessToken(peer, oauthSelection);
		assert.equal(requests.length, 2);
	});

	it("coalesces concurrent cache misses and normalizes invalidation keys", async () => {
		let requests = 0;
		let resolveRequest!: () => void;
		const provider = new OAuthClientCredentialsProvider(
			{ clientId: "id", clientSecret: "secret", trustedTokenEndpointOrigins: ["https://issuer.example"] },
			async () => {
				requests++;
				await new Promise<void>((resolve) => { resolveRequest = resolve; });
				return new Response(JSON.stringify({ access_token: "token", expires_in: 3600 }));
			},
		);
		const normalizedPeer = { ...peer, resource: "https://peer.example" };
		const first = provider.getAccessToken(normalizedPeer, oauthSelection);
		const second = provider.getAccessToken(normalizedPeer, oauthSelection);
		assert.equal(requests, 1);
		resolveRequest();
		await Promise.all([first, second]);
		provider.invalidate(normalizedPeer, oauthSelection);
		const third = provider.getAccessToken(normalizedPeer, oauthSelection);
		resolveRequest();
		await third;
		assert.equal(requests, 2);
	});

	it("does not fall back to a legacy key when an OAuth token request fails", async () => {
		const provider = new OAuthClientCredentialsProvider({ clientId: "id", clientSecret: "secret", trustedTokenEndpointOrigins: ["https://issuer.example"] }, async () => new Response("denied", { status: 401 }));
		await assert.rejects(() => provider.getAccessToken(peer, oauthSelection), /OAuth token request failed/);
	});

	it("rejects unpinned or non-HTTPS token metadata before invoking fetch", async () => {
		let called = false;
		const provider = new OAuthClientCredentialsProvider({ clientId: "id", clientSecret: "secret", trustedTokenEndpointOrigins: ["https://issuer.example"] }, async () => {
			called = true;
			return new Response();
		});
		await assert.rejects(() => provider.getAccessToken({ ...peer, authorizationServer: "http://issuer.example/token" }, oauthSelection), /must be HTTPS/);
		await assert.rejects(() => provider.getAccessToken({ ...peer, authorizationServer: "https://attacker.example/token" }, oauthSelection), /not pinned/);
		assert.equal(called, false);
	});

	it("never sends client credentials to an authorization server from an Agent Card", async () => {
		let called = false;
		const provider = new OAuthClientCredentialsProvider({ clientId: "id", clientSecret: "secret", trustedTokenEndpointOrigins: ["https://issuer.example"] }, async () => {
			called = true;
			return new Response();
		});
		await assert.rejects(
			() => provider.getAccessToken({ ...peer, source: "agent-card" }, oauthSelection),
			/trusted Hub or static directory metadata/,
		);
		assert.equal(called, false);
	});

	it("disables redirects on credential-bearing token requests", async () => {
		let redirect: RequestRedirect | undefined;
		const provider = new OAuthClientCredentialsProvider({ clientId: "id", clientSecret: "secret", trustedTokenEndpointOrigins: ["https://issuer.example"] }, async (_url, init) => {
			redirect = init?.redirect;
			return new Response(JSON.stringify({ access_token: "token" }));
		});
		await provider.getAccessToken(peer, oauthSelection);
		assert.equal(redirect, "error");
	});
});
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall