import { type BearerTokenResponse, type DeviceAccessTokenError, type DeviceAccessTokenResponse, type DeviceAuthorizationResponse } from "./authorize.ts"; import type { ValidatedAuthMetadata } from "./discover.ts"; import { type OAuthRegistrationRequest } from "./register.ts"; import { type Logger } from "../logger.ts"; export * from "./authorize.ts"; export * from "./error.ts"; export * from "./register.ts"; export * from "./discover.ts"; /** * Type representing the persistent context needed for typical OAuth flows */ type Context = { /** The OAuth client ID */ clientId: string; /** The desired device ID */ deviceId?: string; /** The seed used to generate the challenge code */ codeVerifier?: string; }; /** * Options controlling how an {@link OAuth2} instance makes HTTP requests to the authorization server. */ export interface OAuth2HttpOptions { /** * The function to invoke for HTTP requests. Defaults to the global `fetch`. */ fetchFn?: typeof globalThis.fetch; } /** * Options for an individual request made by an {@link OAuth2} instance. */ export interface OAuth2RequestOptions { /** * A signal which, when aborted, aborts the request. */ abortSignal?: AbortSignal; } export declare class OAuth2 { readonly metadata: ValidatedAuthMetadata; private readonly logger; private readonly httpOptions; /** * Attempts dynamic registration against the configured registration endpoint. * Will ignore any URIs that do not use client_uri as a common base as per the spec. * @param authMetadata - Auth config from {@link MatrixClient.getAuthMetadata} * @param clientMetadata - The metadata for the client which to register, * grant_types & response_types & token_endpoint_auth_method will be sanely calculated if omitted. * @param logger - Optional logger to use for the request, defaults to the root logger of the js-sdk. * @returns Promise resolved with registered clientId * @throws when registration is not supported, on failed request or invalid response */ static registerClient(authMetadata: ValidatedAuthMetadata, clientMetadata: OAuthRegistrationRequest, logger?: Logger): Promise; readonly context: Required; /** * @param metadata - The validated OAuth 2.0 metadata for the Identity Provider. * @param context - The persistent context needed for the OAuth flows. * @param logger - Optional logger to use for the requests made by this instance, * defaults to the root logger of the js-sdk. * @param httpOptions - Optional settings controlling how this instance makes HTTP requests. */ constructor(metadata: ValidatedAuthMetadata, context: Context, logger?: Logger, httpOptions?: OAuth2HttpOptions); /** * Generate a URL to attempt authorization with the OP * See https://spec.matrix.org/v1.18/client-server-api/#authorization-code-flow * @param state - A unique opaque identifier, like a transaction ID, * that will allow the client to maintain state between the authorization request and the callback. * The app should use this to key the storage for where the rest of the auth context is saved. * @param responseMode - The manner in which the IdP should send the secrets back to the app. Defaults to `fragment` for privacy. * @param redirectUri - The redirect URI this application is registered with the delegated auth server under. * @param prompt - Optional prompt parameter to pass to the IdP to signal intent, e.g. `create` for User registration. * @param scope - The OAuth2 scope to request, will be generated based on the device ID if omitted. * @returns a Promise with the url as a string */ generateAuthorizationCodeGrantUrl(state: string, redirectUri: string, responseMode?: "fragment" | "query", prompt?: string, scope?: string): Promise; /** * Attempt to exchange authorization code for bearer token. * * Takes the authorization code returned by the OAuth2 Provider via the authorization URL, and makes a * request to the Token Endpoint, to obtain the access token, refresh token, etc. * * @param code - authorization code as returned by IdP during authorization * @returns a validated bearer token response * @throws An `Error` with `message` set to an entry in {@link OAuth2Error}, * when the request fails, or the returned token response is invalid. */ completeAuthorizationCodeGrant(code: string, redirectUri: string): Promise; /** * Refresh the access token using the given refresh token and the refresh token grant * @param refreshToken - the token to use to refresh the access token * @param opts - optional settings for this request */ performRefreshTokenGrant(refreshToken: string, opts?: OAuth2RequestOptions): Promise; /** * Revokes the given token * @param token - the token to remove * @param type - the type of token, acts as a hint to the IdP * @param opts - optional settings for this request */ revokeToken(token: string, type?: "access_token" | "refresh_token", opts?: OAuth2RequestOptions): Promise; /** * Begin OAuth2 device authorization flow. * @param scope - the scope to request for authorization. * @returns a promise that resolves to a device access token response, * or an error response if the user denies authorization or the device code expires. */ startDeviceAuthorizationGrant(scope?: string): Promise; /** * Polls the OAuth2 token endpoint until we get a device access token response, or encounter an unrecoverable error. * @param session - The session returned from a previous call to {@link OAuth2.startDeviceAuthorizationGrant}. * @returns a promise that resolves to a device access token response, * or an error response if the user denies authorization or the device code expires. */ waitForDeviceAuthorizationGrant(session: DeviceAuthorizationResponse): Promise; /** * Make a request to one of the OAuth 2.0 endpoints, throwing if it responds with an error. * * The request is made using the `fetchFn` given in {@link OAuth2HttpOptions}, and is aborted if * `opts.abortSignal` is aborted. * @returns the {@link Response}, for the caller to parse if the endpoint returns a body. */ private fetch; } //# sourceMappingURL=index.d.ts.map