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

See Salesforce DX Usernames and Orgs

// 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 });

Hierarchy

Constructors

Methods

  • Get the org front door (used for web based oauth flows)

    Returns string

  • Convenience function to handle typical side effects encountered when dealing with an AuthInfo. Given the values supplied in parameter sideEffects, this function will set auth alias, default auth and default dev hub.

    Parameters

    Returns Promise<void>

  • Initializes an instance of the AuthInfo class.

    Returns Promise<void>

  • Returns true if this is using an access token flow.

    Returns boolean

  • Returns true if this is using the oauth flow.

    Returns boolean

  • Returns true if this is using the refresh token flow.

    Returns boolean

  • Returns true if this org is using access token auth.

    Returns boolean

  • Sets the provided alias to the username

    Parameters

    • alias: string

      alias to set

    Returns Promise<void>

  • Set the target-env (default) or the target-dev-hub to the alias if it exists otherwise to the username. Method will try to set the local config first but will default to global config if that fails.

    Parameters

    • options: {
          devHub?: boolean;
          org?: boolean;
      } = ...
      • Optional devHub?: boolean
      • Optional org?: boolean

    Returns Promise<void>

  • Get the authorization URL.

    Parameters

    • options: OAuth2Config & {} & {
          scope?: string;
      }

      The options to generate the URL.

    • Optional oauth2: OAuth2

    Returns string

  • Returns the default instance url

    Returns

    Returns string

  • Returns true if one or more authentications are persisted.

    Returns Promise<boolean>

  • Given a set of decrypted fields and an authInfo, determine if the org belongs to an available dev hub.

    Parameters

    Returns Promise<void>

  • Parse a sfdx auth url, usually obtained by authInfo.getSfdxAuthUrl.

    Example

    await AuthInfo.create(AuthInfo.parseSfdxAuthUrl(sfdxAuthUrl));
    

    Parameters

    • sfdxAuthUrl: string

    Returns Pick<AuthFields, "clientId" | "loginUrl" | "clientSecret" | "refreshToken">