import { AsyncCreatable } from '@salesforce/kit'; import { Nullable, Optional } from '@salesforce/ts-types'; import { OAuth2Options } from 'jsforce'; import { Connection } from './connection'; /** * Fields for authorization, org, and local information. */ export interface AuthFields { accessToken?: string; alias?: string; authCode?: string; clientId?: string; clientSecret?: string; created?: string; createdOrgInstance?: string; devHubUsername?: string; instanceUrl?: string; isDevHub?: boolean; loginUrl?: string; orgId?: string; password?: string; privateKey?: string; refreshToken?: string; scratchAdminUsername?: string; snapshot?: string; userId?: string; username?: string; usernames?: string[]; userProfileName?: string; } /** * Options for access token flow. */ export interface AccessTokenOptions { accessToken?: string; loginUrl?: string; instanceUrl?: string; } /** * A function to update a refresh token when the access token is expired. */ export declare type RefreshFn = (conn: Connection, callback: (err: Nullable, accessToken?: string, res?: object) => Promise) => Promise; /** * Options for {@link Connection}. */ export declare type ConnectionOptions = AuthFields & { /** * OAuth options. */ oauth2?: Partial; /** * Refresh token callback. */ refreshFn?: RefreshFn; }; /** * Salesforce URLs. */ export declare enum SfdcUrl { SANDBOX = "https://test.salesforce.com", PRODUCTION = "https://login.salesforce.com" } /** * Handles persistence and fetching of user authentication information using * JWT, OAuth, or refresh tokens. Sets up the refresh flows that jsForce will * use to keep tokens active. An AuthInfo can also be created with an access * token, but AuthInfos created with access tokens can't be persisted to disk. * * **See** [Authorization](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth.htm) * * **See** [Salesforce DX Usernames and Orgs](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm) * * ``` * // Creating a new authentication file. * const authInfo = await AuthInfo.create({ * username: myAdminUsername, * oauth2Options: { * loginUrl, authCode, clientId, clientSecret * } * ); * authInfo.save(); * * // Creating an authorization info with an access token. * const authInfo = await AuthInfo.create({ * username: accessToken * }); * * // Using an existing authentication file. * const authInfo = await AuthInfo.create({ * username: myAdminUsername * }); * * // Using the AuthInfo * const connection = await Connection.create({ authInfo }); * ``` */ export declare class AuthInfo extends AsyncCreatable { /** * Get a list of all auth files stored in the global directory. * @returns {Promise} */ static listAllAuthFiles(): Promise; /** * Returns true if one or more authentications are persisted. */ static hasAuthentications(): Promise; /** * Get the authorization URL. * @param options The options to generate the URL. */ static getAuthorizationUrl(options: OAuth2Options): string; /** * Forces the auth file to be re-read from disk for a given user. Returns `true` if a value was removed. * @param username The username for the auth info to re-read. */ static clearCache(username: string): boolean; private static authFilenameFilterRegEx; private static cache; private fields; private usingAccessToken; private logger; private authInfoCrypto; private options; /** * Constructor * **Do not directly construct instances of this class -- use {@link AuthInfo.create} instead.** * @param options The options for the class instance */ constructor(options: AuthInfo.Options); /** * Get the username. */ getUsername(): Optional; /** * Returns true if `this` is using the JWT flow. */ isJwt(): boolean; /** * Returns true if `this` is using an access token flow. */ isAccessTokenFlow(): boolean; /** * Returns true if `this` is using the oauth flow. */ isOauth(): boolean; /** * Returns true if `this` is using the refresh token flow. */ isRefreshTokenFlow(): boolean; /** * Updates the cache and persists the authentication fields (encrypted). * @param authData New data to save. */ save(authData?: AuthFields): Promise; /** * Update the authorization fields, encrypting sensitive fields, but do not persist. * For convenience `this` object is returned. * * @param authData Authorization fields to update. * @param encrypt Encrypt the fields. */ update(authData?: AuthFields, encrypt?: boolean): AuthInfo; /** * Get the auth fields (decrypted) needed to make a connection. */ getConnectionOptions(): ConnectionOptions; /** * Get the authorization fields. */ getFields(): AuthFields; /** * Returns true if this org is using access token auth. */ isUsingAccessToken(): boolean; /** * Get the SFDX Auth URL. * * **See** [SFDX Authorization](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_auth.htm#cli_reference_force_auth) */ getSfdxAuthUrl(): string; /** * Initializes an instance of the AuthInfo class. */ init(): Promise; /** * Initialize this AuthInfo instance with the specified options. If options are not provided, initialize it from cache * or by reading from the persistence store. For convenience `this` object is returned. * @param options Options to be used for creating an OAuth2 instance. * * **Throws** *{@link SfdxError}{ name: 'NamedOrgNotFound' }* Org information does not exist. * @returns {Promise} */ private initAuthOptions; private isTokenOptions; private refreshFn; private buildJwtConfig; private buildRefreshTokenConfig; private buildWebAuthConfig; private lookup; } export declare namespace AuthInfo { /** * Constructor options for AuthInfo. */ interface Options { /** * Org signup username. */ username?: string; /** * OAuth options. */ oauth2Options?: OAuth2Options; /** * Options for the access token auth. */ accessTokenOptions?: AccessTokenOptions; } }