import { UserManager } from 'oidc-client-ts'; export type OidcConfiguration = { issuer: string; redirect_uri: string; client_id: string; response_type: string; scope: string; post_logout_redirect_uri: string; }; export type LegacyTokens = { acct1: string; acct2?: string; acct3?: string; token1: string; token2?: string; token3?: string; cur1: string; cur2?: string; cur3?: string; }; type RequestOidcAuthenticationOptions = { redirectCallbackUri?: string; postLoginRedirectUri?: string; postLogoutRedirectUri?: string; state?: Record; login_code?: string; }; type requestOidcSilentAuthenticationOptions = { redirectCallbackUri?: string; redirectSilentCallbackUri: string; state?: Record; login_code?: string; }; type RequestOidcTokenOptions = { redirectCallbackUri?: string; postLogoutRedirectUri?: string; }; type CreateUserManagerOptions = { redirectCallbackUri?: string; redirectSilentCallbackUri?: string; postLogoutRedirectUri?: string; }; type OAuth2LogoutOptions = { WSLogoutAndRedirect: () => void; redirectCallbackUri: string; postLogoutRedirectUri: string; }; type ClearOIDCStorageOptions = { redirectCallbackUri: string; postLogoutRedirectUri: string; }; /** * Fetches the OIDC configuration for the given serverUrl. * @returns {Promise} - A promise resolving to the OIDC configuration. * @throws {Error} - If there is a failure while fetching the OIDC configuration. */ export declare const fetchOidcConfiguration: () => Promise; /** * Initiates the OIDC authentication flow by redirecting to Deriv's authorization server. * This is the first step in the OIDC flow, which calls the authorization endpoint and if successful, should redirect back to the callback page. * * Your application must have a callback page with the `Callback` component from this library, or if not, some page that calls the next few endpoints using `requestOidcToken` and `requestLegacyToken` * * @param options - Configuration options for the OIDC authentication request * @param options.redirectCallbackUri - The callback page URI to redirect back * @param options.postLoginRedirectUri - The URI to redirect after the callback page. This is where you usually pass the page URL where you initiated the login flow * @param options.postLogoutRedirectUri - The URI where the application should redirect after processing the logout * * @param options.state - An optional payload you can pass to the authentication flow. This will allow OIDC to carry your state in the callback page, where you can perform additional redirection actions based on the state * * @returns Promise that resolves to an object containing the UserManager instance * @throws {OIDCError} With type AuthenticationRequestFailed if the authentication request fails * * @example * ```typescript * try { * const { userManager } = await requestOidcAuthentication({ * redirectCallbackUri: 'https://smarttrader.deriv.com/en/callback', * postLoginRedirectUri: 'https://smarttrader.deriv.com/en/trading', * postLogoutRedirectUri: https://smarttrader.deriv.com/en/trading', * state: { * redirect_to: '/tradershub/home' * } * }); * } catch (error) { * // Handle authentication request error * } * ``` * * @remarks * - If postLoginRedirectUri is not provided, it defaults to the current window's URL origin, i.e. https://smarttrader.deriv.com instead of https://smarttrader.deriv.com/en/trading * - If postLogoutRedirectUri is not provided, it defaults to the current window's origin, i.e. https://smarttrader.deriv.com instead of https://smarttrader.deriv.com/en/trading * - The post login/logout redirect URIs are stored in local storage as `config.post_login_redirect_uri` and `config.post_logout_redirect_uri` */ export declare const requestOidcAuthentication: (options: RequestOidcAuthenticationOptions) => Promise<{ userManager: UserManager; }>; /** * Initiates the OIDC silent authentication flow by checking the login status in an iframe. * The application will need to have a `/silent-callback` route to handle the silent authentication flow. * * * @param options - Configuration options for the OIDC silent authentication request * @param options.redirectSilentCallbackUri - The silent callback page URI which will be rendered in an iframe to check login status * @param options.state - An optional payload you can pass to the silent authentication flow. This will allow OIDC to carry your state in the callback page, where you can perform additional redirection actions based on the state * * @returns Promise that resolves to an object containing the UserManager instance * @throws {OIDCError} With type AuthenticationRequestFailed if the authentication request fails * * @example * ```typescript * try { * const { userManager } = await requestOidcSilentAuthentication({ * redirectCallbackUri: 'https://smarttrader.deriv.com/en/silent-callback', * * state: { * redirect_to: '/tradershub/home' * } * }); * } catch (error) { * // Handle authentication request error * } * ``` * * @remarks * - An iframe will be generated and embedded in the page, which will send postMessage events to the parent window to indicate the login status */ export declare const requestOidcSilentAuthentication: (options: requestOidcSilentAuthenticationOptions) => Promise<{ userManager: UserManager; } | undefined>; /** * Requests access tokens from the authorization server. * The returned access tokens will be used to fetch the original tokens that can be passed to the `authorize` endpoint. * * This function should only be called when `requestOidcAuthentication` has been called. Generally this function should be placed within the callback page. * * @param options - Configuration options for the OIDC token request * @param options.redirectCallbackUri - The callback page URI to redirect back * @param options.postLogoutRedirectUri - The URI to redirect after successfully logging out * @returns Promise that resolves to an object containing the access token * @returns {Object} result * @returns {string} result.accessToken - The OAuth2/OIDC access token * * @throws {OIDCError} With type AccessTokenRequestFailed if the token request fails * * @example * ```typescript * try { * const { accessToken } = await requestOidcToken({ * redirectCallbackUri: 'https://smarttrader.deriv.com/en/callback' * }); * * // Use the access token for authenticated API calls * } catch (error) { * // Handle token request error * } * ``` * * @remarks * - This function should be called on the callback page/route of your application * - The function expects the OIDC callback parameters to be present in the URL * - The access token can be null if the authentication flow fails or is cancelled */ export declare const requestOidcToken: (options: RequestOidcTokenOptions) => Promise<{ accessToken: string | undefined; user: import('oidc-client-ts').User | undefined; }>; /** * Fetches the tokens that will be passed to the `authorize` endpoint. * * @param {string} accessToken The access token received after calling `requestOidcToken` successfully */ /** * Fetches the tokens that will be passed to the `authorize` endpoint. * * @param {string} accessToken - The OAuth2/OIDC access token obtained from `requestOidcToken` function * @returns {Promise} A promise that resolves to an object containing the legacy tokens * * @throws {OIDCError} With type LegacyTokenRequestFailed if the request fails * * @example * ```typescript * // YourCallbackPage.tsx * try { * const { accessToken } = await requestOidcToken(...) * * const legacyTokens = await requestLegacyToken(accessToken); * * } catch (error) { * // Handle legacy token request error * } * ``` */ export declare const requestLegacyToken: (accessToken: string) => Promise; /** * Revokes legacy tokens by making a POST request to the legacy token revocation endpoint. * Once these tokens are revoked, they can no longer be used for authentication. * * @param {string[]} tokens - An array of legacy tokens (a1-... format) to be revoked. Maximum 20 tokens allowed. * All tokens must belong to the same user and app_id. * @returns {Promise} A promise that resolves when the tokens are successfully revoked * * @throws {OIDCError} With type `RevokeTokenRequestFailed` if: * - The request fails due to network issues (500 Internal Server Error) * - The tokens array is empty or invalid format (400 Bad Request - InvalidPayload) * - The tokens are invalid, already revoked, or belong to different users/app_ids (400 Bad Request - InvalidToken) * - The number of tokens exceeds the maximum limit of 20 (400 Bad Request - InvalidTokenCount) * - Rate limit is exceeded - more than 5 requests per minute (429 Too Many Requests - RateLimit) * * @example * ```typescript * try { * const legacyTokens = [ * 'a1-....', * 'a1-....' * ]; * await revokeLegacyTokens(legacyTokens); * // Tokens successfully revoked * } catch (error) { * if (error instanceof OIDCError) { * // Handle specific revocation errors * console.error(error.message); * } * } * ``` */ export declare const revokeLegacyTokens: (tokens: string[]) => Promise; /** * Creates a UserManager instance that will be used to manage and call the OIDC flow * @param options - Configuration options for the OIDC token request * @param options.redirectCallbackUri - The callback page URI to redirect back * @param options.postLogoutRedirectUri - The URI to redirect after logging out */ export declare const createUserManager: (options: CreateUserManagerOptions) => Promise; /** * Logs out the user from the auth server and calls the callback function when the logout is complete. * @param WSLogoutAndRedirect - The callback function to call after the logout is complete */ export declare const OAuth2Logout: (options: OAuth2LogoutOptions) => Promise; /** * Logs out the user from the OIDC provider using the SignOutRedirect function of the UserManager. * @param {RequestOidcAuthenticationOptions} options - Configuration options for the OIDC logout request * @param {string} options.redirectCallbackUri - The callback page URI to redirect back * @param {string} options.postLogoutRedirectUri - The URI to redirect after successfully logging out * @throws {Error} If the ID token is missing in session storage */ export declare const oidcLogout: (options: RequestOidcAuthenticationOptions) => Promise; /** * Clears any OIDC-related storage (localStorage, sessionStorage, etc) about the current user. * There's 2 types of storage `oidc-client-ts` uses: state store, and user store * User store is used for storing the access token and ID token * Use this function when your application has logged out successfully but the session data is still there, otherwise use `OAuth2Logout` function which already handles this scenario * */ export declare const clearOIDCStorage: (options: ClearOIDCStorageOptions) => Promise; /** * Checks if the user has completed the logout flow and calls the callback function from the consumer. * At this point the user is already logged out from the auth server. This function is just to clear the FE session. * @description This is because the logout flow oidcLogout is redirecting the user to the post logout redirect uri, * so this function needs to be called in your post logout redirect uri to clear the FE session. * @param {() => void} callbackFunction - The callback function to call after the logout is complete * @example * ```typescript * React.useEffect(() => { * handlePostLogout(() => { * // localStorage/sessionStorage cleanup * }); * }, []); }) */ export declare const handlePostLogout: (callbackFunction: () => void) => void; export {};