Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AuthInfo

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

Index

Constructors

constructor

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

    Parameters

    • options: Options

      The options for the class instance

    Returns AuthInfo

Methods

getConnectionOptions

getFields

getSfdxAuthUrl

  • getSfdxAuthUrl(): string

getUsername

  • getUsername(): Optional<string>

init

  • init(): Promise<void>
  • Initializes an instance of the AuthInfo class.

    Returns Promise<void>

isAccessTokenFlow

  • isAccessTokenFlow(): boolean
  • Returns true if this is using an access token flow.

    Returns boolean

isJwt

  • isJwt(): boolean
  • Returns true if this is using the JWT flow.

    Returns boolean

isOauth

  • isOauth(): boolean
  • Returns true if this is using the oauth flow.

    Returns boolean

isRefreshTokenFlow

  • isRefreshTokenFlow(): boolean
  • Returns true if this is using the refresh token flow.

    Returns boolean

isUsingAccessToken

  • isUsingAccessToken(): boolean
  • Returns true if this org is using access token auth.

    Returns boolean

save

  • Updates the cache and persists the authentication fields (encrypted).

    Parameters

    Returns Promise<AuthInfo>

update

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

    • Default value encrypt: boolean = true

      Encrypt the fields.

    Returns AuthInfo

Static clearCache

  • clearCache(username: string): boolean
  • Forces the auth file to be re-read from disk for a given user. Returns true if a value was removed.

    Parameters

    • username: string

      The username for the auth info to re-read.

    Returns boolean

Static create

  • create<P, T>(this: object, options: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the provided options.

    Type parameters

    • P

    • T: AsyncCreatable<P>

    Parameters

    • this: object
    • options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>

Static getAuthorizationUrl

  • getAuthorizationUrl(options: OAuth2Options): string
  • Get the authorization URL.

    Parameters

    • options: OAuth2Options

      The options to generate the URL.

    Returns string

Static hasAuthentications

  • hasAuthentications(): Promise<boolean>
  • Returns true if one or more authentications are persisted.

    Returns Promise<boolean>

Static listAllAuthFiles

  • listAllAuthFiles(): Promise<string[]>
  • Get a list of all auth files stored in the global directory.

    Returns Promise<string[]>