How to use the adal-node.MemoryCache function in adal-node

To help you get started, we’ve selected a few adal-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-node / test / framework / suite-base.js View on Github external
//Recording info
  this.setRecordingsDirectory(__dirname + '/../recordings/' + this.testPrefix + '/');
  this.suiteRecordingsFile = this.getRecordingsDirectory() + 'suite.' + this.testPrefix + '.nock.js';
  this.recordingsFile = __dirname + '/../recordings/' + this.testPrefix + '.nock.js';
  //test modes
  this.isMocked = !process.env.NOCK_OFF;
  this.isRecording = process.env.AZURE_NOCK_RECORD;
  this.isPlayback = !process.env.NOCK_OFF && !process.env.AZURE_NOCK_RECORD;
  //authentication info
  this.subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'] || 'subscription-id';
  this.clientId = process.env['CLIENT_ID'] || DEFAULT_ADAL_CLIENT_ID;
  this.domain = process.env['DOMAIN'] || 'domain';
  this.username = process.env['AZURE_USERNAME'] || 'username@example.com';
  this.password = process.env['AZURE_PASSWORD'] || 'dummypassword';
  this.secret = process.env['APPLICATION_SECRET'] || 'dummysecret';
  this.tokenCache = new adal.MemoryCache();
  this._setCredentials();
  //subscriptionId should be recorded for playback
  if (!env) {
    env = [];
  }
  env.push('AZURE_SUBSCRIPTION_ID');
  // Normalize environment
  this.normalizeEnvironment(env);
  this.validateEnvironment();
  //track & restore generated uuids to be used as part of request url, like a RBAC role assignment name
  this.uuidsGenerated = [];
  this.currentUuid = 0;
  this.randomTestIdsGenerated = [];
  this.numberOfRandomTestIdGenerated = 0;
  this.mockVariables = {};
  //stub necessary methods if in playback mode
github Azure / ng-deploy-azure / src / util / azure / auth.ts View on Github external
return _auth;
  };

  // check old AUTH config from cache
  let auth = (await globalConfig.get(AUTH)) as AuthResponse | null;

  // if old AUTH config is not found, we trigger a new login flow
  if (auth === null) {
    auth = await retryLogin(auth);
  } else {
    const creds = auth.credentials as DeviceTokenCredentials;
    const { clientId, domain, username, tokenAudience, environment } = creds;

    // if old AUTH config was found, we extract and check if the required fields are valid
    if (creds && clientId && domain && username && tokenAudience && environment) {
      const cache = new MemoryCache();
      cache.add(creds.tokenCache._entries, () => {});

      // we need to regenerate a proper object from the saved credentials
      auth.credentials = new DeviceTokenCredentials(
        clientId,
        domain,
        username,
        tokenAudience,
        new Environment(environment),
        cache
      );

      const token = await auth.credentials.getToken();
      // if extracted token has expired, we request a new login flow
      if (new Date(token.expiresOn).getTime() < Date.now()) {
        logger.info(`Your stored credentials have expired; you'll have to log in again`);
github microsoft / botbuilder-js / tools / framework / suite-base.js View on Github external
//Recording info
    this.setRecordingsDirectory(path.join(__dirname, '../../', `libraries/${ libraryPath }/tests/recordings/`));
    this.suiteRecordingsFile = this.getRecordingsDirectory() + 'suite.' + this.testPrefix + '.nock.js';
    //test modes
    // dotenv reads booleans as strings, so we'll use ternary statements to conver to boolean
    this.isMocked = !process.env.NOCK_OFF || process.env.NOCK_OFF != 'true' ? true : false;
    this.isRecording = process.env.AZURE_NOCK_RECORD === 'true' ? true : false;
    this.isPlayback = this.isMocked && !this.isRecording;
    //authentication info
    this.subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'] || 'subscription-id';
    this.clientId = process.env['CLIENT_ID'] || DEFAULT_ADAL_CLIENT_ID;
    this.domain = process.env['DOMAIN'] || 'domain';
    this.username = process.env['AZURE_USERNAME'] || 'username@example.com';
    this.password = process.env['AZURE_PASSWORD'] || 'dummypassword';
    this.secret = process.env['CLIENT_SECRET'] || 'dummysecret';
    this.tokenCache = new adal.MemoryCache();
    
    this._setCredentials();
    //subscriptionId should be recorded for playback
    if (!env) {
        env = [];
    }
    env.push('AZURE_SUBSCRIPTION_ID');
    // Normalize environment
    this.normalizeEnvironment(env);
    this.validateEnvironment();
    //track & restore generated uuids to be used as part of request url, like a RBAC role assignment name
    this.uuidsGenerated = [];
    this.currentUuid = 0;
    this.randomTestIdsGenerated = [];
    this.numberOfRandomTestIdGenerated = 0;
    this.mockVariables = {};
github Azure / autorest / src / client / NodeJS / ms-rest-azure / lib / login.js View on Github external
}

  if (!options.environment) {
    options.environment = AzureEnvironment.Azure;
  }

  if (!options.domain) {
    options.domain = azureConstants.AAD_COMMON_TENANT;
  }

  if (!options.clientId) {
    options.clientId = azureConstants.DEFAULT_ADAL_CLIENT_ID;
  }

  if (!options.tokenCache) {
    options.tokenCache = new adal.MemoryCache();
  }

  if (!options.language) {
    options.language = azureConstants.DEFAULT_LANGUAGE;
  }

  this.tokenAudience = options.tokenAudience;
  this.environment = options.environment;
  this.domain = options.domain;
  this.clientId = options.clientId;
  this.tokenCache = options.tokenCache;
  this.language = options.language;
  var authorityUrl = this.environment.activeDirectoryEndpointUrl + this.domain;
  this.context = new adal.AuthenticationContext(authorityUrl, this.environment.validateAuthority, this.tokenCache);
  var self = this;
  var tenantList = [];
github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / login.js View on Github external
}

  if (!options.environment) {
    options.environment = AzureEnvironment.Azure;
  }

  if (!options.domain) {
    options.domain = azureConstants.AAD_COMMON_TENANT;
  }

  if (!options.clientId) {
    options.clientId = azureConstants.DEFAULT_ADAL_CLIENT_ID;
  }

  if (!options.tokenCache) {
    options.tokenCache = new adal.MemoryCache();
  }

  if (!options.language) {
    options.language = azureConstants.DEFAULT_LANGUAGE;
  }
  let interactiveOptions = {};
  interactiveOptions.tokenAudience = options.tokenAudience;
  interactiveOptions.environment = options.environment;
  interactiveOptions.domain = options.domain;
  interactiveOptions.clientId = options.clientId;
  interactiveOptions.tokenCache = options.tokenCache;
  interactiveOptions.language = options.language;
  interactiveOptions.userCodeResponseLogger = options.userCodeResponseLogger;
  let authorityUrl = interactiveOptions.environment.activeDirectoryEndpointUrl + interactiveOptions.domain;
  interactiveOptions.context = new adal.AuthenticationContext(authorityUrl, interactiveOptions.environment.validateAuthority, interactiveOptions.tokenCache);
  let tenantList = [];
github Azure / azure-sdk-for-java / ClientRuntimes / NodeJS / ms-rest-azure / lib / login.js View on Github external
}

  if (!options.environment) {
    options.environment = AzureEnvironment.Azure;
  }

  if (!options.domain) {
    options.domain = azureConstants.AAD_COMMON_TENANT;
  }

  if (!options.clientId) {
    options.clientId = azureConstants.DEFAULT_ADAL_CLIENT_ID;
  }

  if (!options.tokenCache) {
    options.tokenCache = new adal.MemoryCache();
  }

  if (!options.language) {
    options.language = azureConstants.DEFAULT_LANGUAGE;
  }

  this.environment = options.environment;
  this.domain = options.domain;
  this.clientId = options.clientId;
  this.tokenCache = options.tokenCache;
  this.language = options.language;
  var authorityUrl = this.environment.activeDirectoryEndpointUrl + this.domain;
  this.context = new adal.AuthenticationContext(authorityUrl, this.environment.validateAuthority, this.tokenCache);
  var self = this;
  var tenantList = [];
  async.waterfall([
github Azure / autorest / src / client / NodeJS / ms-rest-azure / lib / credentials / applicationTokenCredentials.js View on Github external
}
  
  if (!options) {
    options = {};
  }
  
  if (!options.environment) {
    options.environment = AzureEnvironment.Azure;
  }
  
  if (!options.authorizationScheme) {
    options.authorizationScheme = Constants.HeaderConstants.AUTHORIZATION_SCHEME;
  }

  if (!options.tokenCache) {
    options.tokenCache = new adal.MemoryCache();
  }

  if (options.tokenAudience) {
    if (options.tokenAudience.toLowerCase() !== 'graph') {
      throw new Error('Valid value for \'tokenAudience\' is \'graph\'.');
    }
    if (domain.toLowerCase() === 'common') {
      throw new Error('If the tokenAudience is specified as \'graph\' then \'domain\' cannot be the default \'commmon\' tenant. ' + 
        'It must be the actual tenant (preferrably a string in a guid format).');
    }
  }

  this.tokenAudience = options.tokenAudience;
  this.environment = options.environment;
  this.authorizationScheme = options.authorizationScheme;
  this.tokenCache = options.tokenCache;
github Azure / ms-rest-nodeauth / lib / login.ts View on Github external
options = {};
  }
  if (!options.environment) {
    options.environment = Environment.AzureCloud;
  }

  if (!options.domain) {
    options.domain = AuthConstants.AAD_COMMON_TENANT;
  }

  if (!options.clientId) {
    options.clientId = AuthConstants.DEFAULT_ADAL_CLIENT_ID;
  }

  if (!options.tokenCache) {
    options.tokenCache = new adal.MemoryCache();
  }

  if (!options.language) {
    options.language = AuthConstants.DEFAULT_LANGUAGE;
  }

  if (!options.tokenAudience) {
    options.tokenAudience = options.environment.activeDirectoryResourceId;
  }
  const interactiveOptions: any = {};
  interactiveOptions.tokenAudience = options.tokenAudience;
  interactiveOptions.environment = options.environment;
  interactiveOptions.domain = options.domain;
  interactiveOptions.clientId = options.clientId;
  interactiveOptions.tokenCache = options.tokenCache;
  interactiveOptions.language = options.language;
github Azure / ms-rest-nodeauth / dist / lib / login.js View on Github external
options = {};
        }
        if (!options) {
            options = {};
        }
        if (!options.environment) {
            options.environment = ms_rest_azure_env_1.AzureEnvironment.Azure;
        }
        if (!options.domain) {
            options.domain = authConstants_1.AuthConstants.AAD_COMMON_TENANT;
        }
        if (!options.clientId) {
            options.clientId = authConstants_1.AuthConstants.DEFAULT_ADAL_CLIENT_ID;
        }
        if (!options.tokenCache) {
            options.tokenCache = new adal.MemoryCache();
        }
        if (!options.language) {
            options.language = authConstants_1.AuthConstants.DEFAULT_LANGUAGE;
        }
        const interactiveOptions = {};
        interactiveOptions.tokenAudience = options.tokenAudience;
        interactiveOptions.environment = options.environment;
        interactiveOptions.domain = options.domain;
        interactiveOptions.clientId = options.clientId;
        interactiveOptions.tokenCache = options.tokenCache;
        interactiveOptions.language = options.language;
        interactiveOptions.userCodeResponseLogger = options.userCodeResponseLogger;
        const authorityUrl = interactiveOptions.environment.activeDirectoryEndpointUrl + interactiveOptions.domain;
        const authContext = new adal.AuthenticationContext(authorityUrl, interactiveOptions.environment.validateAuthority, interactiveOptions.tokenCache);
        interactiveOptions.context = authContext;
        let userCodeResponse;

adal-node

Windows Azure Active Directory Client Library for node

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis