The Access Token Entity

The AccessToken class represents authorization to use the SDK as a specific, authenticated user. See Authentication for more details and examples.

Summary of Properties and Methods

Static Properties

NameTypeDescription
defaultAccessTokenAttempt to load and return an Access Token from the default env var or file location
DEFAULT_ACCESS_TOKEN_DIRstringGets the default path for saved Access Token files. Resolves to $HOME/.catalytic/tokens or equivalent

Static Methods

NameReturn TypeDescription
fromFileAccessTokenAttempt to load and return an Access Token from a file
fromStringAccessTokenDeserialize an Access Token from a serialized Access Token string
fromEnvAccessTokenDeserialize an Access Token from the CATALYTIC_TOKEN
env var
listAccessTokensDictionary
<string, AccessToken>
Lists all Access Tokens stored as files in the given path
or in the default path
deleteAccessTokenFilevoidDelete an Access Token file

Constructor

const { AccessToken } = require('@catalytic/sdk');
const accessToken = new AccessToken('YOUR_SERIALIZED_ACCESS_TOKEN_STRING');
ParameterTypeDescription
tokenstringThe serialized Access Token string, available on creation of new Access Token via UI or SDK

Instance Properties

NameTypeDescription
namestringThe name of the AccessToken
idstringThe unique ID of the AccessToken
secretstringThe deserialized secret of the AccessToken
domainstringThe Domain of the Catalytic team with which these AccessToken are associated
tokenstringThe serialized AccessToken Token
environmentstringThe environment of the Catalytic team associated with the AccessToken
ownerstringThe email address of the user to whom these AccessToken belong
typestringThe type of the AccessToken. Possible values include only 'user', currently

Instance Methods

NameReturn TypeDescription
saveToFilevoidSaves the serialized AccessToken to a file, allowing for easy loading in the future

Constructors

AccessTokens can be constructed by passing the serialized AccessToken string to the AccessToken constructor. See Authentication for more details on accessing the serialized AccessToken string.

AccessToken(token: string)
const accessToken = new AccessToken('YOUR_SERIALIZED_ACCESS_TOKEN_STRING');

The fromFile Static Method

Load an Access Token by name from the default Access Token directory, a given directory or a specific file location. The default directory is AccessToken.DEFAULT_ACCESS_TOKEN_DIR, which will be $HOME/.catalytic/tokens or the equivalent depending on the OS.

Method Signature

fromFile(fileNameOrPath: string): AccessToken;
ParameterTypeDescription
fileNameOrPathstringThe file name or file path of the Access Token on disk. If provided value
does not resolve to a file on disk, the value will interpreted as a filename within the
default AccessTokens directory ($HOME/.catalytic/tokens)
returnsAccessTokenThe deserialized Access Token

The fromEnv Static Method

Deserializes an Access Token from a token string stored in the CATALYTIC_TOKEN env var.

Method Signature

static AccessToken fromEnv()
ParameterTypeDescription
returnsAccessTokenThe deserialized Access Token

The listAccessTokens Static Method

Gets all Access Tokens stored in a given directory, or in the default Access Token directory if none is specified. The default directory is AccessToken.DEFAULT_ACCESS_TOKEN_DIR, which will be $HOME/.catalytic/tokens or the equivalent depending on the OS.

Method Signature

listAccessTokens(accessTokensDirectory?: string): { [accessTokenName: string]: AccessToken }
ParameterTypeDescription
accessTokensDirectoryDirectoryInfoOptional Access Token directory, defaults to
AccessToken.DEFAULT_ACCESS_TOKEN_DIR
returnsObject<string, AccessToken>An object containing the deserialized Access Tokens in the given (or default) directory, keyed by file name.

The deleteAccessTokenFile Static Method

Deletes saved Access Token. Note that this does not permanently revoke the Access Token. To permanently revoke an Access Token, use the Catalytic Web App

Method Signature

deleteAccessTokenFile(fileNameOrPath: string): void;
ParameterTypeDescription
fileNameOrPathstringThe file name or file path of the Access Token on disk. If provided value
does not resolve to a file on disk, the value will interpreted as a filename within the
default AccessTokens directory ($HOME/.catalytic/tokens)

The saveToFile Instance Method

Saves an Access Token to a file, allowing for load via AccessToken.fromFile. Throws AccessTokenNameConflictException if the file already exists.

public saveToFile(fileName: string): void;
public saveToFile(fileName: string, directoryPath: string): void;
ParameterTypeDescription
fileNamestringThe name of the Access Token file
directoryPathstringOptional Path to Access Tokens directory, defaults to
AccessToken.DEFAULT_ACCESS_TOKEN_DIR