import type { AuthStrategy, AccessTokenResponse, DecodedJWT, FetchInit } from './types.js'; /** * Configuration for the implicit OAuth flow. */ export interface ImplicitOAuthConfig { /** OAuth client ID registered with Account Manager */ clientId: string; /** OAuth scopes to request (e.g., 'sfcc.products', 'sfcc.orders') */ scopes?: string[]; /** Account Manager host (defaults to 'account.demandware.com') */ accountManagerHost?: string; /** * Local port for the OAuth redirect server. * Defaults to 8080 or SFCC_OAUTH_LOCAL_PORT environment variable. */ localPort?: number; /** * Full redirect URI for OAuth. Use when running behind a proxy where * localhost cannot be reached directly by the browser. * Defaults to `http://localhost:${localPort}` or SFCC_REDIRECT_URI environment variable. * The local server still listens on localPort regardless of this setting. */ redirectUri?: string; /** * Custom browser opener. Receives the authorization URL and should open it * in the user's browser. Useful in environments where the default `open` package * doesn't work (e.g., VS Code remote/Codespaces where `vscode.env.openExternal` is needed). */ openBrowser?: (url: string) => Promise; } /** * OAuth 2.0 Implicit Grant Flow authentication strategy. * * This strategy is used when only a client ID is available (no client secret). * It opens a browser for the user to authenticate with Account Manager, * then captures the access token from the OAuth redirect. * * Note: The access token from implicit flow is valid for 30 minutes and cannot be renewed. * This flow requires user interaction and a TTY. * * @example * ```typescript * import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk'; * * const auth = new ImplicitOAuthStrategy({ * clientId: 'your-client-id', * scopes: ['sfcc.products', 'sfcc.orders'], * }); * * // Will open browser for authentication * const response = await auth.fetch('https://example.com/api/resource'); * ``` */ export declare class ImplicitOAuthStrategy implements AuthStrategy { private config; private accountManagerHost; private localPort; private redirectUri; private _hasHadSuccess; /** * Creates a new ImplicitOAuthStrategy instance. * * @param config - OAuth implicit flow configuration containing clientId, optional scopes, accountManagerHost, localPort, redirectUri, and openBrowser callback. */ constructor(config: ImplicitOAuthConfig); fetch(url: string, init?: FetchInit): Promise; getAuthorizationHeader(): Promise; /** * Gets the decoded JWT payload */ getJWT(): Promise; /** * Gets the full token response including expiration and scopes. * Useful for commands that need to display or return token metadata. */ getTokenResponse(): Promise; /** * Invalidates the cached token, forcing re-authentication on next request */ invalidateToken(): void; /** * Gets an access token, using cache if valid. * Uses a mutex to prevent concurrent auth flows for the same clientId. */ private getAccessToken; /** * Performs an implicit OAuth2 login flow. * Opens the user's browser for authentication with Account Manager. * * NOTE: This method requires a TTY and user intervention; it is interactive. * NOTE: Access token is valid for 30 minutes and cannot be renewed. */ private implicitFlowLogin; }