UNPKG

@adinsure-ops/ops-cli

Version:

Operations CLI for working with AdInsure

103 lines (102 loc) 3.7 kB
/// <reference types="node" /> import { ParsedUrlQuery } from 'querystring'; /** * Security context that keeps track of current authentication token. * It's not recommended you instantiate this class on your own but rather inherit your commands from [[CommandBase]]. */ export default class SecurityContext { private readonly clientId; private readonly devopsResourceId; private readonly managementCoreWindowsNet; private readonly tenant; private readonly tenantId; private readonly registry; private readonly authorityUrl; private readonly redirectUri; private readonly resource; private readonly _accessTokenPath; private readonly _accessTokenRuPath; private readonly _accessConfigPath; private readonly _pca; private readonly _cryptoProvider; private _verifier; private _challenge; /** * Initializes [[SecurityContext]] with config directory where access token JSON will be stored. * @param configDir Directory where CLI configuration is stored */ constructor(configDir: string); /** * Get the accessTokenPath, as it is a private variable * @returns {string} Returns access token path */ getTokenPath(): string; /** * Get the accessTokenRuPath, as it is a private variable * @returns {string} Returns access token Ru path */ getTokenRuPath(): string; /** * Get the accessConfigPath, as it is a private variable * @returns {string} Returns config.json path */ getConfigPath(): string; /** * Contacts authority server, fetches and saves the authentication token to be used in subsequent requests. * * @param code Authorization code used to fetch the token. * @returns [[Promise<TokenResponse>]] */ getLoginUrl(): Promise<string>; /** * Retrieves the refresh token from the MSAL (Microsoft Authentication Library) token cache. * * @returns {string} The refresh token. * * @example * const refreshToken = getRefreshToken(); * console.log(refreshToken); * * @description * The `getRefreshToken` function extracts the refresh token from the serialized token cache * managed by the MSAL library. This function first serializes the token cache, parses it into * a JSON object, and then retrieves the refresh token from the parsed object. * * @throws {Error} If there are issues with parsing the token cache or accessing the refresh token. */ getRefreshToken(): string; /** * Gets the current authentication token. * This function will also automatically try to refresh token if expired. * * @throws Error when authentication failed and/or call to login is needed * @returns Promise that resolves bearer authentication token */ getToken(): Promise<string>; /** * Fetches the locally stored token for GitlabRu * @returns authentication token for gitlabru.adacta-fintech.ru */ getTokenRu(): string; getAADToken(): Promise<string>; getACRToken(): Promise<string>; /** * Contacts authority server, fetches and saves the authentication token to be used in subsequent requests. * * @param query Authorization query used to fetch the token. * @returns [[Promise<TokenResponse>]] */ acquireToken(query: ParsedUrlQuery): Promise<string>; /** * Acquires token using device flow. * * @returns [[Promise<TokenResponse>]] */ acquireTokenDeviceFlow(): Promise<void>; /** * Get NPM token for adinsure npm repositories * * @returns [[Promise<string>]] */ getNPMToken(): Promise<string>; }