import { ApplicationTokenCredentialsBase } from "./applicationTokenCredentialsBase" ; import { Environment } from "@azure/ms-rest-azure-env" ; import { AuthConstants , TokenAudience } from "../util/authConstants" ; import { TokenResponse , ErrorResponse , TokenCache } from "adal-node" ; export class ApplicationTokenCredentials extends ApplicationTokenCredentialsBase { readonly secret : string ; /**
     * Creates a new ApplicationTokenCredentials object.
     * See  https * for detailed instructions on creating an Azure Active Directory application.
     *
     *  param clientId param domain param secret param tokenAudience param environment param tokenCache public constructor ( clientId , domain , secret , tokenAudience ? , environment ? , tokenCache ? ) { if ( ! secret || typeof secret . valueOf ( ) !== "string" ) { throw new Error ( "secret must be a non empty string." ) ; } super ( clientId , domain , tokenAudience , environment , tokenCache ) ; this . secret = secret ; } returns public async getToken ( ) { try { return await this . getTokenFromCache ( ) ; } catch ( error ) { if ( error . message && error . message . startsWith ( AuthConstants . SDK_INTERNAL_ERROR ) ) { throw error ; } const resource = this . getActiveDirectoryResourceId ( ) ; return new Promise ( ( resolve , reject ) => { this . authContext . acquireTokenWithClientCredentials ( resource , this . clientId , this . secret , ( error , tokenResponse ) => { if ( error ) { return reject ( error ) ; } if ( tokenResponse . error || tokenResponse . errorDescription ) { return reject ( tokenResponse ) ; } return resolve ( tokenResponse as TokenResponse ) ; } ) ; } ) ; } } }