How to use the ms-rest.Constants function in ms-rest

To help you get started, we’ve selected a few ms-rest 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 / runtime / ms-rest-azure / lib / credentials / msiVmTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

// jshint ignore: start
// Note that this file is jshint clean except for properties inside token response 
// which are not camel cased and they are issued by the MSI service, 
// we do not control the shape of the response object.

'use strict';

const msrest = require('ms-rest');
const request = require('request');
const Constants = msrest.Constants;

const MSITokenCredentials = require('./msiTokenCredentials');

class MSIVmTokenCredentials extends MSITokenCredentials {
  constructor(options) {
    if (!options) options = {};
    super(options);
    if (!options.port) {
      options.port = 50342; // default port where token service runs.
    } else if (typeof options.port.valueOf() !== 'number') {
      throw new Error('port must be a number.');
    }
    
    this.port = options.port;
  }
github Azure / azure-sdk-for-java / ClientRuntimes / NodeJS / ms-rest-azure / lib / credentials / userTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

var util = require('util');
var msrest = require('ms-rest');
var adal = require('adal-node');
var Constants = msrest.Constants;

var AzureEnvironment = require('../azureEnvironment');

/**
* Creates a new UserTokenCredentials object.
*
* @constructor
* @param {string} clientId The active directory application client id. 
* See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} 
* for an example.
* @param {string} domain The domain or tenant id containing this application.
* @param {string} username The user name for the Organization Id account.
* @param {string} password The password for the Organization Id account.
* @param {string} clientRedirectUri The Uri where the user will be redirected after authenticating with AD.
* @param {object} [options] Object representing optional parameters.
* @param {AzureEnvironment} [options.environment] The azure environment to authenticate with.
github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / credentials / deviceTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

'use strict';

const msrest = require('ms-rest');
const adal = require('adal-node');
const Constants = msrest.Constants;
const azureConstants = require('../constants');
const AzureEnvironment = require('../azureEnvironment');

/**
 * Creates a new DeviceTokenCredentials object that gets a new access token using userCodeInfo (contains user_code, device_code)
 * for authenticating user on device.
 *
 * When this credential is used, the script will provide a url and code. The user needs to copy the url and the code, paste it 
 * in a browser and authenticate over there. If successful, the script will get the access token.
 *
 * @constructor
 * @param {object} [options] Object representing optional parameters.
 * @param {string} [options.username] The user name for account in the form: 'user@example.com'.
 * @param {AzureEnvironment} [options.environment] The azure environment to authenticate with. Default environment is "Azure" popularly known as "Public Azure Cloud".
 * @param {string} [options.domain] The domain or tenant id containing this application. Default value is 'common'
 * @param {string} [options.tokenAudience] The audience for which the token is requested. Valid value is 'graph'. If tokenAudience is provided 
github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / credentials / msiTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

// jshint ignore: start
// Note that this file is jshint clean except for properties inside token response 
// which are not camel cased and they are issued by the MSI service, 
// we do not control the shape of the response object.

'use strict';

const msrest = require('ms-rest');
const Constants = msrest.Constants;

/**
 * Base class for MSI based credentials
 */
class MSITokenCredentials {

  /**
   * Creates an instance of MSITokenCredentials.
   * @param {object} [options] - Optional parameters
   * @param {string} [options.resource] - The resource uri or token audience for which the token is needed.
   * For e.g. it can be:
   * - resourcemanagement endpoint "https://management.azure.com"(default) 
   * - management endpoint "https://management.core.windows.net/"
   */
  constructor(options) {
    if (!options) options = {};
github Azure / autorest / src / client / NodeJS / ms-rest-azure / lib / credentials / applicationTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

var util = require('util');
var msrest = require('ms-rest');
var adal = require('adal-node');
var Constants = msrest.Constants;

var AzureEnvironment = require('../azureEnvironment');

/**
* Creates a new ApplicationTokenCredentials object.
* See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} 
* for detailed instructions on creating an Azure Active Directory application.
* @constructor
* @param {string} clientId The active directory application client id. 
* @param {string} domain The domain or tenant id containing this application.
* @param {string} secret The authentication secret for the application.
* @param {object} [options] Object representing optional parameters.
* @param {string} [options.tokenAudience] The audience for which the token is requested. Valid value is 'graph'. If tokenAudience is provided 
* then domain should also be provided its value should not be the default 'common' tenant. It must be a string (preferrably in a guid format).
* @param {AzureEnvironment} [options.environment] The azure environment to authenticate with.
* @param {string} [options.authorizationScheme] The authorization scheme. Default value is 'bearer'.
github Azure / azure-sdk-for-java / ClientRuntimes / NodeJS / ms-rest-azure / lib / credentials / applicationTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

var util = require('util');
var msrest = require('ms-rest');
var adal = require('adal-node');
var Constants = msrest.Constants;

var AzureEnvironment = require('../azureEnvironment');

/**
* Creates a new ApplicationTokenCredentials object.
* See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} 
* for detailed instructions on creating an Azure Active Directory application.
* @constructor
* @param {string} clientId The active directory application client id. 
* @param {string} domain The domain or tenant id containing this application.
* @param {string} secret The authentication secret for the application.
* @param {object} [options] Object representing optional parameters.
* @param {AzureEnvironment} [options.environment] The azure environment to authenticate with.
* @param {string} [options.authorizationScheme] The authorization scheme. Default value is 'bearer'.
* @param {object} [options.tokenCache] The token cache. Default value is null.
*/
github Azure / azure-sdk-for-java / ClientRuntimes / NodeJS / ms-rest-azure / lib / credentials / applicationTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

var util = require('util');
var msrest = require('ms-rest');
var adal = require('adal-node');
var Constants = msrest.Constants;

var AzureEnvironment = require('../azureEnvironment');

/**
* Creates a new ApplicationTokenCredentials object.
* See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} 
* for detailed instructions on creating an Azure Active Directory application.
* @constructor
* @param {string} clientId The active directory application client id. 
* @param {string} domain The domain or tenant id containing this application.
* @param {string} secret The authentication secret for the application.
* @param {object} [options] Object representing optional parameters.
* @param {AzureEnvironment} [options.environment] The azure environment to authenticate with.
* @param {string} [options.authorizationScheme] The authorization scheme. Default value is 'bearer'.
* @param {object} [options.tokenCache] The token cache. Default value is the MemoryCache object from adal.
*/
github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / credentials / keyVaultCredentials.js View on Github external
// 

'use strict';
/* jshint latedef:false */

const url = require('url');
const msRest = require('ms-rest');
const ApplicationTokenCredentials = require('./applicationTokenCredentials');
const UserTokenCredentials = require('./userTokenCredentials');
const DeviceTokenCredentials = require('./deviceTokenCredentials');
const MSITokenCredentials = require('./msiTokenCredentials');
const MSIVmTokenCredentials = require('./msiVmTokenCredentials');
const MSIAppServiceTokenCredentials = require('./msiAppServiceTokenCredentials');

const AuthenticationContext = require('adal-node').AuthenticationContext;
let HeaderConstants = msRest.Constants.HeaderConstants;
let requestPipeline = msRest.requestPipeline;


function authenticatorMapper(credentials) {
  return function (challenge, callback) {
    // Function to take token Response and format a authorization value
    function _formAuthorizationValue(err, tokenResponse) {
      if (err) {
        return callback(err);
      }
      // Calculate the value to be set in the request's Authorization header and resume the call.
      var authorizationValue = tokenResponse.tokenType + ' ' + tokenResponse.accessToken;

      return callback(null, authorizationValue);
    }
github Azure / azure-sdk-for-node / runtime / ms-rest-azure / lib / credentials / userTokenCredentials.js View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. 

'use strict';

const msrest = require('ms-rest');
const adal = require('adal-node');
const Constants = msrest.Constants;
const AzureEnvironment = require('../azureEnvironment');

function _retrieveTokenFromCache(callback) {
  /* jshint validthis: true */
  let self = this;
  let resource = this.environment.activeDirectoryResourceId;
  if (self.tokenAudience)  {
    resource = self.tokenAudience;
    if (self.tokenAudience.toLowerCase() === 'graph') {
      resource = self.environment.activeDirectoryGraphResourceId;
    } else if (self.tokenAudience.toLowerCase() === 'batch') {
      resource = self.environment.batchResourceId;
    }
  }
  this.context.acquireToken(resource, this.username, this.clientId, function (err, result) {
    if (err) return callback(err);
github Azure / azure-sdk-for-node / lib / services / batch / lib / batchSharedKeyCredentials.js View on Github external
/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is
 * regenerated.
 */

var msrest = require('ms-rest');
var _ = require('underscore');
var url = require('url');

var Constants = msrest.Constants;
var HmacSha256Sign = require('./hmacsha256');

/**
 * @class 
 * Creates a new BatchSharedKeyCredentials object.
 * @constructor
 * @param {string} accountName The batch account name. 
 * @param {string} accountKey The batch account key.
 */
function BatchSharedKeyCredentials(accountName, accountKey) {
  if (!Boolean(accountName) || typeof accountName.valueOf() !== 'string') {
    throw new Error('accountName must be a non empty string.');
  }

  if (!Boolean(accountKey) || typeof accountKey.valueOf() !== 'string') {
    throw new Error('accountKey must be a non empty string.');