/** * AgentIdentity — flow-selection + token acquisition for agent-to-MCP-server access. * * Implements §10 of the Agent Identity spec: * 1. Discover Protected Resource Metadata (RFC 9728) * 2. Discover AS metadata (RFC 8414) * 3. Decide direct vs XAA (based on preferredMode + requester-bootstrap) * 4. Run the chosen path and return a short-lived access token, or throw * a typed PendingApproval when access is still being reviewed. * * Usage (service-to-service M2M, API credential): * * const identity = new AgentIdentity({ * issuer: 'https://auth.example.com', * clientId: 'my-service-client-id', * clientSecret: 'sk-...', * }); * const token = await identity.accessFor('https://payments.example.com/mcp'); * // → pass token as Bearer in every MCP tool call. * * Usage (XAA cross-app, user-delegated): * * const identity = new AgentIdentity({ * issuer: 'https://auth.example.com', * clientId: 'my-agent-client-id', * idpIssuer: 'https://idp.enterprise.com', * preferredMode: 'auto', * }); * const token = await identity.accessFor('https://payments.example.com/mcp', { * userSession: { subject_token: '...' }, * requestedScopes: ['tickets.read'], * }); */ export declare class AuthSecIdentityError extends Error { readonly code: string; readonly httpStatus?: number; constructor(code: string, message: string, httpStatus?: number); } /** Access was requested and is awaiting admin approval. Poll statusUrl. */ export declare class PendingApprovalError extends AuthSecIdentityError { readonly requestId: string; readonly statusUrl: string; constructor(requestId: string, statusUrl: string); } /** An admin declined the access request. */ export declare class ApprovalDeniedError extends AuthSecIdentityError { constructor(); } /** The agent connection was revoked. */ export declare class ConnectionRevokedError extends AuthSecIdentityError { constructor(); } /** The issuer is not trusted by the AuthSec instance. */ export declare class TrustedIssuerMissingError extends AuthSecIdentityError { constructor(); } /** Subject mapping from external identity to local user failed. */ export declare class SubjectMappingFailedError extends AuthSecIdentityError { constructor(); } /** The MCP server URI is not registered. */ export declare class ResourceNotRegisteredError extends AuthSecIdentityError { constructor(resource: string); } /** The client credential is invalid. */ export declare class CredentialInvalidError extends AuthSecIdentityError { constructor(detail?: string); } /** The workload has not yet attested via SPIFFE. */ export declare class WorkloadNotAttestedError extends AuthSecIdentityError { constructor(); } export type PreferredMode = 'auto' | 'direct-only' | 'xaa-allowed'; export interface AgentIdentityConfig { /** AuthSec AS issuer URL (e.g. https://auth.example.com) */ issuer: string; /** OAuth client_id for this agent */ clientId: string; /** Client secret (client_secret_basic). Mutually exclusive with privateKey. */ clientSecret?: string; /** JWKS private key for private_key_jwt. Mutually exclusive with clientSecret. */ privateKey?: { key: unknown; kid: string; }; /** Enterprise IdP issuer for XAA subject tokens. Required for XAA paths. */ idpIssuer?: string; /** Flow preference. Default: 'auto' */ preferredMode?: PreferredMode; /** Override the token endpoint (discovered by default). */ tokenEndpoint?: string; /** HTTP fetch implementation (default: globalThis.fetch). */ fetch?: typeof fetch; } export interface AccessForOptions { /** OIDC subject token from the enterprise IdP (required for XAA user-delegated path). */ userSession?: { subject_token: string; subject_token_type?: string; }; /** Scopes to request. Defaults to the role scopes negotiated at bootstrap. */ requestedScopes?: string[]; /** Additional parameters forwarded to the token endpoint. */ extra?: Record; } export declare class AgentIdentity { private readonly cfg; private readonly _fetch; private readonly _cache; constructor(config: AgentIdentityConfig); /** * Obtain a short-lived access token for `resource`. * * Returns the token string on success. * Throws PendingApprovalError when access is requested but not yet approved. * Throws other AuthSecIdentityError subclasses for terminal failures. */ accessFor(resource: string, options?: AccessForOptions): Promise; /** Clear cached tokens (e.g. after receiving a 401 to force re-mint). */ clearCache(resource?: string): void; private _acquireToken; private _direct; private _xaa; private _tokenExchange; private _requesterBootstrap; private _handleBootstrapUnavailable; private _discoverPRM; private _discoverAS; private _authBodyParams; private _tokenRequest; private _throwFromErrorBody; private _authHeaders; } export interface PollOptions { /** How often to poll in ms. Default: 2000 */ intervalMs?: number; /** Max attempts before giving up. Default: 150 (~5 minutes at 2s interval) */ maxAttempts?: number; /** Custom fetch implementation. Default: globalThis.fetch */ fetch?: typeof fetch; /** AbortSignal to cancel polling. */ signal?: AbortSignal; } /** * Poll `statusUrl` until the access request is approved, then call * `identity.clearCache(resource)` and retry `accessFor`. * * Usage: * try { * token = await identity.accessFor(resource); * } catch (err) { * if (err instanceof PendingApprovalError) { * token = await pollUntilApproved(identity, resource, err.statusUrl); * } else throw err; * } */ export declare function pollUntilApproved(identity: AgentIdentity, resource: string, statusUrl: string, options?: PollOptions & { accessForOptions?: AccessForOptions; }): Promise; //# sourceMappingURL=agent-identity.d.ts.map