import { TokenEndpointRequestOptions } from 'oauth4webapi'; import { Ref } from 'vue'; import { Storage } from './Storage'; import * as oauth from 'oauth4webapi'; export type OAuthClientOptions = { /** * The URL of the OAuth issuer. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * ``` */ url: string; /** * The client ID of the applicatio. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * ``` */ clientId: string; /** * The client authentication method, see {@link oauth.ClientAuthenticationMethod} * @default 'none' public client * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-2.3) * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication) * @see [OAuth Token Endpoint Authentication Methods](https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#token-endpoint-auth-method) * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * tokenEndpointAuthMethod: 'client_secret_basic' * }) * ``` */ tokenEndpointAuthMethod?: oauth.ClientAuthenticationMethod; /** * The scopes requested to the OAuth server. * @default '' * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * scopes: 'openid profile email' * }) * ``` */ scopes?: string[] | string; /** * The storage to use for persisting the refresh token. * @default * `new LocalStorage('oauth')` * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * storage: new SessionStorage('my-app') * }) * ``` */ storage?: Storage; /** * The redirect URI. * @default * `document.location.origin` * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * redirectUri: 'https://my-app.com/callback' * }) * ``` */ redirectUri?: string; /** * The URL to redirect the user after the logout. * @default * `document.location.origin` * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * postLogoutRedirectUri: 'https://my-app.com' * }) * ``` */ postLogoutRedirectUri?: string; }; type UndefinedOrNullString = string | undefined | null; export declare class OAuthClient { private _client; private _issuer; private _scope; private _storage; private _redirectUri; private _postLogoutRedirectUri; private _refreshToken; private _accessToken; private _codeVerifier; private _authorizationServer?; constructor(options: OAuthClientOptions); /** * Extends the client options. * @param options - The options to change. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * client.extend({ * scopes: 'openid profile email' * }) * ``` */ extend: (options: OAuthClientOptions) => void; /** * Initializes the client and tries to refresh the token if a refresh token is available, see {@link refreshToken}. * or handle the code response if a code verifier is available, see {@link handleCodeResponse}. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * ``` */ initialize: (options?: TokenEndpointRequestOptions & { accessToken?: string; }) => Promise>>; /** * Authorize the application redirecting the client to the authorization server. * @throws If the client is not initialized. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * await client.authorize() * ``` */ authorize: () => Promise; /** * Handle the authorization code response. * @throws If the client is not initialized. * @param urlParams - The URL parameters. */ handleCodeResponse: (urlParams: URLSearchParams) => Promise>>; /** * Refresh the access token. * @throws If the client is not initialized. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * await client.refreshToken() * ``` * @returns The new access token. */ refreshToken: (options?: TokenEndpointRequestOptions) => Promise>>; /** * Logout the user. * @param logoutHint - The hint to the Authorization Server about the End-User that is logging out. * @throws If the client is not initialized. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * client.logout() * ``` */ logout: (logoutHint?: string) => void; /** * Reactive value indicating whether the user is logged in. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * if (client.loggedIn.value) { * // User is logged in * } * ``` */ get loggedIn(): import('vue').ComputedRef; /** * Reactive value indicating the access token. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * await client.initialize() * if (client.loggedIn.value) { * // User is logged in * console.log(client.accessToken.value) * } * ``` */ get accessToken(): Readonly>; /** * Indicates whether the client has been initialized. * @example * ```typescript * const client = new OAuthClient({ * url: 'https://example.com', * clientId: 'my-client-id', * }) * if (!client.initialized) { * await client.initialize() * } * ``` */ get initialized(): boolean; } export {};