Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adal-node

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adal-node - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2-beta.0

5

changelog.md

@@ -0,1 +1,6 @@

Version 0.2.2-beta
------------------
Release Date: 1 February 2020
* Replace 'request` with `axios`
Version 0.2.0

@@ -2,0 +7,0 @@ ------------------

0

lib/adal.d.ts

@@ -0,0 +0,0 @@ import * as http from "http";

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

52

lib/authentication-parameters.js

@@ -24,4 +24,3 @@ /*

var request = require('request');
var axios = require('axios');
var argument = require('./argument');

@@ -179,9 +178,9 @@ var log = require('./log');

if (!response.statusCode) {
throw new Error('The response parameter does not have the expected HTTP statusCode field');
if (!response.status) {
throw new Error('The response parameter does not have the expected HTTP status field');
}
if (HttpErrorCode.UNAUTHORIZED !== response.statusCode) {
if (HttpErrorCode.UNAUTHORIZED !== response.status) {
throw new Error('The response status code does not correspond to an OAuth challenge. ' +
'The statusCode is expected to be 401 but is: ' + response.statusCode);
'The status is expected to be 401 but is: ' + response.status);
}

@@ -243,19 +242,38 @@

logger.verbose('Attempting to retrieve authentication parameters from: ' + challengeUrl, true);
var options = util.createRequestOptions( { _callContext : { _logContext: logContext } } );
request.get(challengeUrl, options, function(err, response) {
if (err) {
logger.error('Authentication parameters http get failed.', err, true);
callback(err);
return;
}
var options = util.createRequestOptions({ _callContext: { _logContext: logContext } });
// TODO: Check if this is alright
axios.get(challengeUrl, options).then((response) => {
var parameters;
try {
parameters = exports.createAuthenticationParametersFromResponse(response);
} catch(creationErr) {
logger.error('Unable to parse response in to authentication paramaters.', creationErr, true);
} catch (creationErr) {
logger.error('Unable to parse response in to authentication parameters.', creationErr, true);
callback(creationErr);
return;
}
callback(null, parameters);
});
}).catch((error) => {
// status >= 400: error case
if (error.response) {
var parameters;
try {
parameters = exports.createAuthenticationParametersFromResponse(error.response);
} catch (creationErr) {
logger.error('Unable to parse response in to authentication parameters.', creationErr, true);
callback(creationErr);
return;
}
callback(null, parameters);
}
// if there is no response from the server
else if (error.request) {
logger.error('AuthenticationParameters' + ' request was made but no response was received', error.request, true);
callback(logger.createError('No response from the server'));
}
// request was never made
else {
logger.error('AuthenticationParameters http get failed.' + ' request was never made, please check', error.message, true);
callback(error.message);
}
})
} catch(err) {

@@ -262,0 +280,0 @@ callback(err);

@@ -23,3 +23,3 @@ /*

var request = require('request');
var axios = require('axios');
var url = require('url');

@@ -172,13 +172,34 @@ var _ = require('underscore');

this._log.verbose('Attempting instance discover at: ' + url.format(discoveryEndpoint), true);
request.get(discoveryEndpoint, getOptions, util.createRequestHandler('Instance Discovery', this._log, callback,
function(response, body) {
var discoveryResponse = JSON.parse(body);
if (discoveryResponse['tenant_discovery_endpoint']) {
callback(null, discoveryResponse['tenant_discovery_endpoint']);
} else {
callback(self._log.createError('Failed to parse instance discovery response'));
}
})
);
axios.get(discoveryEndpoint, getOptions).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'Instance Discovery' + ' request returned http error: ' + response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(this._log.createError(returnErrorString, true), response.data);
}
// Success case: status >= 200 && < 300
var discoveryResponse = response.data;
if (discoveryResponse['tenant_discovery_endpoint']) {
callback(null, discoveryResponse['tenant_discovery_endpoint']);
} else {
callback(self._log.createError('Failed to parse instance discovery response'));
}
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('Instance Discovery' + ' request failed with', error.response.status, true);
var returnErrorString = 'Instance Discovery' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(self._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if(error.request) {
this._log.error('Instance Discovery' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else {
this._log.error('Instance Discovery' + ' request was never made, please check', error.message, true);
callback(error.message);
}
});
} catch(e) {

@@ -185,0 +206,0 @@ callback(e);

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -22,3 +22,3 @@ /*

'use strict';
var request = require('request');
var axios = require('axios');
var url = require('url');

@@ -83,7 +83,13 @@ var DOMParser = require('xmldom').DOMParser;

var self = this;
var options = util.createRequestOptions(self, { headers : { 'Content-Type' : 'application/soap+xml'} });
request.get(this._url, options, util.createRequestHandler('Mex Get', this._log, callback,
function(response, body) {
try {
self._mexDoc = body;
var options = util.createRequestOptions(self, { headers: { 'Content-Type': 'application/soap+xml' } });
axios.get(this._url, options).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'Mex Get' + ' request returned http error: ' + response.status + ' and server response: ' + response.status;;
callback(this._log.createError(returnErrorString, true), response.data);
}
// Success case: status >= 200 && < 300
try {
self._mexDoc = response.data;
var options = {

@@ -99,4 +105,20 @@ errorHandler : self._log.error

}
})
);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('Mex Get' + ' request failed with', error.response.status, true);
var returnErrorString = 'Mex Get' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);;
callback(self._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if (error.request) {
this._log.error('Mex Get' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else {
this._log.error('Mex Get' + ' request was never made, please check', error.message, true);
callback(error.message);
}
});
};

@@ -103,0 +125,0 @@

@@ -27,3 +27,3 @@ /*

var uuid = require('uuid');
var request = require('request');
var axios = require('axios');
var url = require('url');

@@ -248,3 +248,3 @@ var async = require('async');

*/
OAuth2Client.prototype._validateTokenResponse = function(body) {
OAuth2Client.prototype._validateTokenResponse = function (body) {
var wireResponse;

@@ -254,3 +254,3 @@ var tokenResponse = {};

try {
wireResponse = JSON.parse(body);
wireResponse = body;
} catch(e) {

@@ -311,3 +311,3 @@ throw new Error('The token response returned from the server is unparseable as JSON');

try {
wireResponse = JSON.parse(body);
wireResponse = body;
} catch(e) {

@@ -364,3 +364,3 @@ throw new Error('The device code response returned from the server is unparseable as JSON.');

try {
wireResponse = JSON.parse(body);
wireResponse = body;
} catch (e) {

@@ -384,3 +384,3 @@ throw new Error ('The token response returned from the server is unparsable as JSON');

*/
OAuth2Client.prototype._handleGetTokenResponse = function(response, body, callback) {
OAuth2Client.prototype._handleGetTokenResponse = function(body, callback) {
var tokenResponse;

@@ -397,3 +397,3 @@ try {

OAuth2Client.prototype._handleGetDeviceCodeResponse = function(response, body, callback) {
OAuth2Client.prototype._handleGetDeviceCodeResponse = function(body, callback) {
var deviceCodeResponse;

@@ -417,42 +417,55 @@ try {

}
request.post(postOptions, util.createRequestHandler('Get Token', this._log, function(response, body) {
//error response callback, for error response, it's already parsed as Json.
if (body && body.hasOwnProperty(TokenResponseFields.ERROR) && body[TokenResponseFields.ERROR] === 'authorization_pending') {
callback(new Error(body[TokenResponseFields.ERROR]), body);
axios(postOptions).then((response) => {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(response.data);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
callback(null, tokenResponse);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
// error response callback, for error response, it's already parsed as Json.
if (error.response && error.response.data.hasOwnProperty(TokenResponseFields.ERROR) && error.response.data[TokenResponseFields.ERROR] === 'authorization_pending') {
callback(new Error(error.response.data[TokenResponseFields.ERROR]), error.response.data);
}
else {
callback(null, body);
}
},
// success response callback
function (response, body) {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(body);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
callback(null, tokenResponse);
})
);
}
// if there is no response from the server
else if (error.request) {
self._log.error('GetToken' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else if (error.message) {
self._log.error('GetToken http get failed.' + ' request was never made, please check', error.message, true);
callback(error.message);
}
// unknown error
else {
self._log.error('GetToken' + ' failed with unknown error', "unknown error", true);
callback(self._log.createError('failed with an unknown error'));
}
});
};
OAuth2Client.prototype._createPostOption = function (postUrl, urlEncodedRequestForm) {
var postOptions = util.createRequestOptions(
this,
{
'url' : url.format(postUrl),
body : urlEncodedRequestForm,
{
method : 'POST',
url : url.format(postUrl),
data : urlEncodedRequestForm,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
},
followRedirect : false,
encoding : 'utf8'
maxRedirects: 0,
encoding: 'utf8',
}
);
return postOptions;

@@ -478,10 +491,35 @@ };

var urlEncodedTokenRequestForm = querystring.stringify(oauthParameters);
var postOptions = self._createPostOption(tokenUrl, urlEncodedTokenRequestForm);
request.post(postOptions, util.createRequestHandler('Get Token', this._log, callback,
function (response, body) {
self._handleGetTokenResponse(response, body, callback);
})
);
axios(postOptions).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'Get Token' + ' request returned http error: ' + response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(this._log.createError(returnErrorString, true), response.data);
}
// Success case: status >= 200 && < 300
self._handleGetTokenResponse(response.data, callback);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('Get Token' + ' request failed with', error.response.status, true);
var returnErrorString = 'Get Token' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(self._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if (error.request) {
this._log.error('Get Token' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else if (error.message) {
this._log.error('Get Token' + ' request was never made, please check', error.message, true);
callback(error.message);
}
// unknown error
else {
self._log.error('GetToken' + ' failed with unknown error', "unknown error", true);
callback(self._log.createError('failed with an unknown error'));
}
});
};

@@ -529,10 +567,36 @@

var postOptions = self._createPostOption(deviceCodeUrl, urlEncodedDeviceCodeRequestForm);
axios(postOptions).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'Get Device Code' + ' request returned http error: ' + response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(this._log.createError(returnErrorString, true), response.data);
}
// Success case: status >= 200 && < 300
self._handleGetDeviceCodeResponse(response.data, callback);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('Get Device Code' + ' request failed with', error.response.status, true);
var returnErrorString = 'Get Device Code' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(self._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if (error.request) {
this._log.error('Get Device Code' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else if (error.message) {
this._log.error('Get Device Code' + ' request was never made, please check', error.message, true);
callback(error.message);
}
// unknown error
else {
self._log.error('Get Device Code' + ' failed with unknown error', "unknown error", true);
callback(self._log.createError('failed with an unknown error'));
}
});
};
request.post(postOptions, util.createRequestHandler('Get Device Code ', this._log, callback,
function (response, body) {
self._handleGetDeviceCodeResponse(response, body, callback);
})
);
};
/**

@@ -539,0 +603,0 @@ * Cancel the polling request made for acquiring token by device code.

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -24,3 +24,3 @@ /*

var querystring = require('querystring');
var request = require('request');
var axios = require('axios');
var _ = require('underscore');

@@ -207,3 +207,3 @@ var url = require('url');

try {
response = JSON.parse(body);
response = body;
} catch (err) {

@@ -263,9 +263,31 @@ callback(this._log.createError('Parsing realm discovery respone JSON failed: ' + body, true));

this._log.verbose('Performing user realm discovery at: ' + url.format(userRealmUrl), true);
request.get(userRealmUrl, options, util.createRequestHandler('User Realm Discovery', this._log, callback,
function(response, body) {
self._parseDiscoveryResponse(body, callback);
})
);
axios.get(userRealmUrl, options).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'User Realm Discovery' + ' request returned http error: ' + response.status + ' and server response: ' + response.status;
callback(this._log.createError(returnErrorString, true), response.data);
}
// Success case: status >= 200 && < 300
self._parseDiscoveryResponse(response.data, callback);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('User Realm Discovery' + ' request failed with', error.response.status, true);
var returnErrorString = 'User Realm Discovery' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(this._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if (error.request) {
this._log.error('User Realm Discovery' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else {
this._log.error('User Realm Discovery' + ' request was never made, please check', error.message, true);
callback(error.message);
}
});
};
module.exports = UserRealm;

@@ -0,0 +0,0 @@ /*

@@ -23,3 +23,3 @@ /*

var request = require('request');
var axios = require('axios');
var uuid = require('uuid');

@@ -217,2 +217,4 @@

{
method: 'POST',
url: this._wstrustEndpointUrl,
headers : {

@@ -222,3 +224,5 @@ 'Content-Type' : 'application/soap+xml; charset=utf-8',

},
body : RST
data: RST,
maxRedirects: 0,
encoding: 'utf8',
}

@@ -229,7 +233,33 @@ );

request.post(this._wstrustEndpointUrl, options, util.createRequestHandler('WS-Trust RST', this._log, callback,
function(response, body) {
self._handleRSTR(body, callback);
axios(options).then((response) => {
// status >= 300 && < 400
if (!util.isHttpSuccess(response.status)) {
var returnErrorString = 'WS-Trust RST' + ' request returned http error: ' + response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(this._log.createError(returnErrorString, true), response.data);
}
));
// Success case: status >= 200 && < 300
self._handleRSTR(response.data, callback);
}).catch((error) => {
// status >= 400: error case
if (error.response) {
this._log.error('WS-Trust RST' + ' request failed with', error.response.status, true);
var returnErrorString = 'WS-Trust RST' + ' request returned http error: ' + error.response.status + ' and server response: ' + JSON.stringify(error.response.data);
callback(self._log.createError(returnErrorString, true), error.response.data);
}
// if there is no response from the server
else if (error.request) {
this._log.error('WS-Trust RST' + ' request was made but no response was received', error.request, true);
callback(self._log.createError('No response from the server'));
}
// request was never made
else if (error.message) {
this._log.error('WS-Trust RST' + ' request was never made, please check', error.message, true);
callback(error.message);
}
// unknown error
else {
self._log.error('WS-Trust RST' + ' failed with unknown error', "unknown error", true);
callback(self._log.createError('failed with an unknown error'));
}
});
};

@@ -236,0 +266,0 @@

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /*

@@ -13,3 +13,3 @@ {

},
"version": "0.2.1",
"version": "0.2.2-beta.0",
"description": "Windows Azure Active Directory Client Library for node",

@@ -34,7 +34,7 @@ "keywords": [

"jws": "3.x.x",
"request": "^2.88.0",
"underscore": ">= 1.3.1",
"uuid": "^3.1.0",
"xmldom": ">= 0.1.x",
"xpath.js": "~1.1.0"
"xpath.js": "~1.1.0",
"axios": "^0.21.1"
},

@@ -41,0 +41,0 @@ "devDependencies": {

@@ -5,4 +5,4 @@ # Windows Azure Active Directory Authentication Library (ADAL) for Node.js

## Versions
Current version - 0.1.28
Minimum recommended version - 0.1.22
Current version - 0.2.2
Minimum recommended version - 0.2.2
You can find the changes for each version in the [change log](https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/master/changelog.txt).

@@ -9,0 +9,0 @@

@@ -0,0 +0,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc