import { type WorkloadJwtVerifier } from "../identity/WorkloadJwtVerifier.js"; /** RFC 8693's grant type, and the token types a subject token may be stated as. */ export declare const TOKEN_EXCHANGE_GRANT = "urn:ietf:params:oauth:grant-type:token-exchange"; /** What the exchange issues: an opaque token for this gateway, never a bearer anywhere else. */ export declare const ISSUED_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token"; /** The most sessions held at once; beyond it a new one is refused rather than an old one dropped. */ export declare const MAX_SESSIONS = 10000; /** How old a subject token may be: a short-lived token, minted for the conversation at hand. */ export declare const MAX_SUBJECT_TOKEN_AGE_SECONDS = 3600; /** A subject the gateway has pinned: who, until when, and a short digest that names the session in evidence. */ export interface SubjectSession { readonly subject: string; readonly expiresAt: number; /** `sha256:` and 12 hex characters of the token's digest; never the token. */ readonly id: string; } /** Why a request's session does not stand: the code a caller sees and the evidence records. */ export type SessionRefusal = "SUBJECT_SESSION_INVALID" | "SUBJECT_TOKEN_INVALID" | "SUBJECT_TOKEN_AMBIGUOUS"; /** A verified subject token: the subject it names and when it expires, in epoch milliseconds. */ export interface VerifiedSubject { readonly subject: string; readonly expiresAt: number; } /** Turns a subject token into the subject it names, or throws `JwtError`. */ export interface SubjectTokenVerifier { verify(token: string): Promise; } /** * The operator's identity provider: a signature from its key set, its issuer * exactly, the gateway's audience, a token at most an hour old, and the * subject in the configured claim, a string or a number of at most 200 * characters. Who the customer is, is the provider's statement; the gateway * only pins it. */ export declare class IssuerSubjectVerifier implements SubjectTokenVerifier { private readonly jwt; private readonly issuer; private readonly claim; constructor(jwt: WorkloadJwtVerifier, issuer: string, claim: string); verify(token: string): Promise; } /** The token exchange's answer: RFC 8693 §2.2, or an RFC 6749 §5.2 error. */ export type ExchangeAnswer = { readonly status: 200; readonly body: { readonly access_token: string; readonly issued_token_type: typeof ISSUED_TOKEN_TYPE; readonly token_type: "N_A"; readonly expires_in: number; }; /** The session, for the evidence line; its token is in the body only. */ readonly session: SubjectSession; } | { readonly status: 400 | 503; readonly body: { readonly error: string; readonly error_description: string; }; }; /** * Subject-bound sessions. The app that starts an agent (a contact centre, a * CRM, a customer's own portal) holds a short-lived token from its identity * provider naming the customer in context. It gives the gateway that token, * and the gateway pins the subject for the session: * * - by RFC 8693 token exchange: `POST /_agentsafe/v1/sessions` returns an * opaque session token, which the agent presents in `AgentSafe-Session`; * the gateway keeps only the token's digest, beside the subject; * - or per request, the provider's token itself in `AgentSafe-Subject-Token`. * * Either way the subject comes from the provider's signature and nothing the * agent sends can change it: the session token maps to a subject held here, * and the provider's token is verified on every request. Both headers end at * the gateway. A session lasts as long as this gateway process: it is held in * memory, so behind several replicas present the provider's token per * request, or keep a caller on one replica. */ export declare class SubjectSessions { private readonly verifier; private readonly options; private readonly sessions; /** * The session each subject token was last exchanged for, by the token's * digest: exchanging a token again replaces its session rather than add * one, so one token cannot fill the gateway's sessions. */ private readonly byToken; constructor(verifier: SubjectTokenVerifier, options: { readonly ttlSeconds: number; readonly clock: () => number; readonly maxSessions?: number; }); /** The sessions held now, expired ones dropped first. */ get size(): number; /** * RFC 8693 token exchange: a subject token in, a session token out. The * request is the form the RFC defines; an actor token (delegation) is not * accepted, and the only token issued is this gateway's session token. A * token that does not verify is `invalid_request`, as the RFC says, with * the stable code as its description and nothing from the token. */ exchange(form: URLSearchParams): Promise; /** * The session a request presents: null when it presents none, the session * when it stands, and the refusal otherwise. A request may present one of * the two headers, never both, since two would be two answers to whose * session it is. */ resolve(headers: Readonly>): Promise; private expire; private static digest; } //# sourceMappingURL=SubjectSessions.d.ts.map