@telstra/core
Version:
Telstra SDK Core
94 lines (93 loc) • 3.79 kB
TypeScript
import { IAuthConfigProps, IAuthCredentials, IAuthManager, IAuthTokenData } from '../index.js';
import { LoggerMixin } from '../../logging/index.js';
/**
* @class AuthManager
* @description AuthManager will handle getting credentials from the user in order of precedence:
* 1. object passed to the constructor
* 2. a file in ~/.telstra/credentials
* 3. environment variables
* @implements IAuthManager
* @extends LoggerMixin
* @exports AuthManager
* @public
* @instance
* @version 1.0.0
*/
export declare class AuthManager extends LoggerMixin implements IAuthManager {
private readonly authConfig?;
hasCredentials: boolean;
private readonly _credentials;
private readonly _configurationService;
constructor(authConfig?: IAuthConfigProps | undefined);
/**
* @method _credentialsFromFileImport
* @description Retrieves credentials from the object passed to the constructor.
* @memberof AuthManager
* @private
* @async
* @instance
* @returns {Promise<boolean>} Returns a promise that resolves to true if the credentials are successfully retrieved, otherwise false.
*/
private _credentialsFromFileImport;
/**
* @method _credentialsFromEnv
* @description Retrieves credentials from the environment variables TELSTRA_CLIENT_ID and TELSTRA_CLIENT_SECRET.
* @memberof AuthManager
* @private
* @async
* @instance
* @returns {Promise<boolean>} Returns a promise that resolves to true if the credentials are successfully retrieved, otherwise false.
*/
private _credentialsFromEnv;
/**
* @method _parseCredentialsFile
* @description Parses the credentials file and returns a Map of profiles and their respective key value pairs.
* @memberof AuthManager
* @private
* @async
* @instance
* @param {string} data - The data read from the credentials file.
* @returns {CredentialsMap} Returns a Map of profiles and their respective key value pairs.
*/
private _parseCredentialsFile;
/**
* @method _credentialsFromObjectImport
* @description Retrieves credentials from the shared credentials file located at ~/.telstra/credentials.json. The file should be in the following format:
* Users can specify a profile in the environment variable TELSTRA_PROFILE. The syntax for profiles is:
* @example
* [default]
* TELSTRA_CLIENT_ID=client_id
* TELSTRA_CLIENT_SECRET=client_secret
*
* [dev]
* TELSTRA_CLIENT_ID=client_id
* TELSTRA_CLIENT_SECRET=client_secret
*
* [prod]
* TELSTRA_CLIENT_ID=client_id
* TELSTRA_CLIENT_SECRET=client_secret
*
* @memberof AuthManager
* @private
* @async
* @instance
* @returns {Promise<boolean>} Returns a promise that resolves to true if the credentials are successfully retrieved, otherwise throws an error.
* @throws {InvalidProfileNameError} Profile not found if the specified profile does not exist in the credentials file.
*/
private _credentialsFromObjectImport;
/**
* Validates the client ID and client secret pair and give a detailed message
* about which one or both is missing
*
* @private
* @param {string} client_id - The client ID to validate.
* @param {string} client_secret - The client secret to validate.
* @throws {CredentialsError} Throws an error if either the client ID or client secret is missing.
*/
private _validateClientPair;
getCredentials(): Promise<IAuthCredentials>;
getAuthTokenData(): Promise<IAuthTokenData | null>;
setAuthTokenData(authTokenData: IAuthTokenData): Promise<boolean>;
setAuthTokenRetryCount(count: number): Promise<boolean>;
resetAuthToken(): Promise<boolean>;
}