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

  • Constructor Do not directly construct instances of this class -- use AuthInfo.create instead.

    Parameters

    Returns AuthInfo

Methods

  • Get the authorization fields.

    Parameters

    • Optional decrypt: boolean

      Decrypt the fields.

      Returns a ReadOnly object of the fields. If you need to modify the fields, use AuthInfo.update()

    Returns Readonly<AuthFields>

  • 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 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>

  • Update the authorization fields, encrypting sensitive fields, but do not persist. For convenience this object is returned.

    Parameters

    • Optional authData: AuthFields

      Authorization fields to update.

    Returns AuthInfo

  • Get the authorization URL.

    Parameters

    • options: OAuth2Config & {
          authCode?: string;
          privateKey?: string;
          privateKeyFile?: string;
          refreshToken?: string;
          username?: string;
      } & {
          scope?: string;
      }

      The options to generate the URL.

    • Optional oauth2: OAuth2

    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, or if the org is a sandbox of another CLI authed production org.

    Parameters

    Returns Promise<void>

  • Get a list of all authorizations based on auth files stored in the global directory. One can supply a filter (see

    Parameters

    • orgAuthFilter: ((orgAuth) => boolean) = ...

      A predicate function that returns true for those org authorizations that are to be retained.

    Returns Promise<OrgAuthorization[]>

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

    Parameters

    • sfdxAuthUrl: string

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

    Example

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