import { type DiscoverOidcMetadataInput, type ExchangeAuthorizationCodeInput, type FetchSessionInfoInput, type FetchUserInfoInput, type OidcDiscoveryMetadata, type OidcSessionInfo, type OidcTokenResponse, type RefreshAccessTokenInput, type RevokeTokenInput } from '@dereekb/util'; /** * The fetch transport injected into every relying-party network call. * * Matches the global `fetch` signature so callers can pass raw `fetch`, a traced/timeout wrapper, * or a `configureFetch(...)` result interchangeably. * * ⚠️ The transport passed to the token-endpoint calls (`exchangeAuthorizationCode`, * `refreshAccessToken`, `revokeToken`, `discoverOidcMetadata`) MUST be a plain fetch — it must NOT * inject an `Authorization: Bearer` header. Public PKCE clients authenticate via the * `code_verifier`, not the access token; a Bearer-injecting transport belongs only on the * resource-server (API) client. */ export type OidcRelyingPartyFetch = typeof fetch; /** * Mixed into each network function's input to inject the {@link OidcRelyingPartyFetch} transport. */ export interface OidcRelyingPartyFetchInput { readonly fetch: OidcRelyingPartyFetch; } /** * Fetches the OIDC discovery document for the given issuer, trying the candidates returned by * {@link buildOidcDiscoveryCandidates} in order. * * @param input - The discovery request plus the injected fetch transport. * @param input.issuer - The OIDC issuer URL whose `.well-known/openid-configuration` is fetched first. * @param input.fallbackBaseUrl - Optional sibling base URL tried after the issuer-prefixed and origin-rooted candidates. * @param input.fetch - The plain fetch transport. * @returns The parsed {@link OidcDiscoveryMetadata}. Throws an {@link OidcRelyingPartyError} (`DISCOVERY_FAILED`) when every candidate fails. */ export declare function discoverOidcMetadata(input: DiscoverOidcMetadataInput & OidcRelyingPartyFetchInput): Promise; /** * Exchanges an authorization code (from the redirect) for an access token + refresh token. * * Sends `client_secret` only when provided — public PKCE clients (`token_endpoint_auth_method: 'none'`) * authenticate via the `code_verifier` alone. * * @param input - The token exchange parameters plus the injected fetch transport. * @param input.tokenEndpoint - The OIDC token endpoint URL discovered from the issuer. * @param input.clientId - The OAuth client ID. * @param input.clientSecret - Optional client secret; omit for public clients. * @param input.clientAuth - How the client secret is presented. Defaults to `client_secret_post`. * @param input.redirectUri - The redirect URI registered with the OAuth client. * @param input.code - The authorization code returned to the redirect URI. * @param input.codeVerifier - The PKCE code verifier originally paired with the code challenge. Omitted when the authorization request sent no challenge. * @param input.fetch - The plain fetch transport. * @returns The parsed {@link OidcTokenResponse} with access/refresh tokens. */ export declare function exchangeAuthorizationCode(input: ExchangeAuthorizationCodeInput & OidcRelyingPartyFetchInput): Promise; /** * Exchanges a refresh token for a new access token (and possibly a rotated refresh token). * * @param input - The refresh request plus the injected fetch transport. * @param input.tokenEndpoint - The OIDC token endpoint URL discovered from the issuer. * @param input.clientId - The OAuth client ID. * @param input.clientSecret - Optional client secret; omit for public clients. * @param input.clientAuth - How the client secret is presented. Defaults to `client_secret_post`. * @param input.refreshToken - The cached refresh token to redeem. * @param input.fetch - The plain fetch transport. * @returns The parsed {@link OidcTokenResponse} with the refreshed access token. */ export declare function refreshAccessToken(input: RefreshAccessTokenInput & OidcRelyingPartyFetchInput): Promise; /** * Revokes an access or refresh token at the OIDC revocation endpoint. * * @param input - The revocation request plus the injected fetch transport. * @param input.revocationEndpoint - The OIDC revocation endpoint URL. * @param input.clientId - The OAuth client ID. * @param input.clientSecret - Optional client secret; omit for public clients. * @param input.clientAuth - How the client secret is presented. Defaults to `client_secret_post`. * @param input.token - The access or refresh token to revoke. * @param input.tokenTypeHint - Optional hint passed as `token_type_hint` (`access_token` or `refresh_token`). * @param input.fetch - The plain fetch transport. * @returns Resolves when the server returns a non-error status. Throws an {@link OidcRelyingPartyError} (`TOKEN_REVOCATION_FAILED`) on error. */ export declare function revokeToken(input: RevokeTokenInput & OidcRelyingPartyFetchInput): Promise; /** * Fetches the OIDC `userinfo` endpoint and returns the parsed claims object. * * @param input - The userinfo request plus the injected fetch transport. * @param input.userinfoEndpoint - The OIDC userinfo endpoint URL discovered from the issuer. * @param input.accessToken - The Bearer access token sent in the `Authorization` header. * @param input.fetch - The fetch transport. * @returns The parsed userinfo claims. Throws an {@link OidcRelyingPartyError} (`USERINFO_FAILED`) on a non-OK response. */ export declare function fetchUserInfo(input: FetchUserInfoInput & OidcRelyingPartyFetchInput): Promise>; /** * Fetches the dbx-components `GET /oidc/session` route and returns the parsed session lifetime metadata. * * Mirrors {@link fetchUserInfo}, but reads the access token's baked-in session-lifetime claims * (`dbx_session_expires_at` / `dbx_rotation_disabled`) which userinfo does not echo. * * @param input - The session request plus the injected fetch transport. * @param input.sessionEndpoint - The `GET /oidc/session` endpoint URL. * @param input.accessToken - The Bearer access token sent in the `Authorization` header. * @param input.fetch - The fetch transport. * @returns The parsed {@link OidcSessionInfo}. Throws an {@link OidcRelyingPartyError} (`SESSION_INFO_FAILED`) on a non-OK response. */ export declare function fetchSessionInfo(input: FetchSessionInfoInput & OidcRelyingPartyFetchInput): Promise;