import type { CredentialResolver } from "./types.ts"; /** * Signing in to a model provider with an account rather than an API key. * * **Everything here is configuration.** No provider is named, no client id is * built in, and no endpoint is hardcoded. That is on purpose: whether a * particular provider permits a third-party client to sign a person in, and on * what terms, is that provider's decision and it changes. The person deploying * this picks a provider they are permitted to use and supplies its details. * * This implements the OAuth 2.0 Device Authorization Grant (RFC 8628), which is * the flow for a client that cannot host a browser redirect. */ export type DeviceCodeConfig = { /** Where to ask for a device code. */ deviceAuthorizationUrl: string; /** Where to exchange an approved device code for a token. */ tokenUrl: string; clientId: string; scope?: string; /** Extra fields both requests carry. */ extraParams?: Record; }; export type DeviceCodeStart = { deviceCode: string; /** The code a person types into the page below. */ userCode: string; /** The page a person opens to approve. */ verificationUri: string; /** The same page with the code already filled in, when the provider offers it. */ verificationUriComplete?: string; expiresInSeconds: number; intervalSeconds: number; }; export type DeviceCodeToken = { accessToken: string; refreshToken?: string; /** Unix milliseconds, or null when the provider gave no expiry. */ expiresAt: number | null; }; /** Somewhere to keep a token between requests. Supply one, or tokens die with the process. */ export interface TokenStore { read(subject: string): Promise; write(subject: string, token: DeviceCodeToken): Promise; } /** A token store in this process's memory. Fine for one server, useless for several. */ export declare class MemoryTokenStore implements TokenStore { #private; read(subject: string): Promise; write(subject: string, token: DeviceCodeToken): Promise; } /** Ask the provider for a device code. Show the person the code and the page. */ export declare function startDeviceLogin(config: DeviceCodeConfig): Promise; /** One poll. Null means the person has not approved yet. */ export declare function pollDeviceLogin(config: DeviceCodeConfig, deviceCode: string): Promise; /** Exchange a refresh token for a fresh access token. */ export declare function refreshDeviceToken(config: DeviceCodeConfig, refreshToken: string): Promise; /** * A credential from a stored sign-in. * * `subjectOf` says which stored token this request may use. It defaults to a * single shared token, which suits one operator signing in once. A multi-reader * deployment must return something per reader, or every reader spends the same * account. */ export declare function fromDeviceLogin(config: DeviceCodeConfig, store: TokenStore, subjectOf?: (request: Request | null) => string): CredentialResolver; //# sourceMappingURL=oauth.d.ts.map