Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit b48bbd7

Browse files
committed
Merge branch 'dev'
2 parents 53cf4c8 + 25b1ba8 commit b48bbd7

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 0.1.20
2+
--------------
3+
Release Date: 17 Jun 2016
4+
* Add support for resource owner grant flow for ADFS
5+
16
Version 0.1.19
27
--------------
38
Release Date: 26 Apr 2016

lib/authority.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ function Authority(authorityUrl, validateAuthority) {
4242
this._validateAuthorityUrl();
4343

4444
this._validated = !validateAuthority;
45-
4645
this._host = null;
4746
this._tenant = null;
4847
this._parseAuthority();
4948

5049
this._authorizationEndpoint = null;
5150
this._tokenEndpoint = null;
5251
this._deviceCodeEndpoint = null;
52+
this._isAdfsAuthority = (this._tenant.toLowerCase() === "adfs");
5353
}
5454

5555
/**
@@ -233,7 +233,7 @@ Authority.prototype._getOAuthEndpoints = function(tenantDiscoveryEndpoint, callb
233233
if (!this._deviceCodeEndpoint){
234234
this._deviceCodeEndpoint = url.format(this._url) + AADConstants.DEVICE_ENDPOINT_PATH;
235235
}
236-
236+
237237
callback();
238238
return;
239239
}

lib/token-request.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ TokenRequest.prototype._getTokenWithCacheWrapper = function(callback, getTokenFu
164164
};
165165

166166
/**
167-
* Store token into cache.
168-
* @param {object} tokenResponse Token response to be added into the cache.
167+
* Store token into cache.
168+
* @param {object} tokenResponse Token response to be added into the cache.
169169
*/
170170
TokenRequest.prototype._addTokenIntoCache = function(tokenResponse, callback) {
171171
this._cacheDriver = this._createCacheDriver();
@@ -275,7 +275,7 @@ TokenRequest.prototype._performWSTrustAssertionOAuthExchange = function(wstrustR
275275
/**
276276
* Exchange a username and password for a SAML token from an ADFS instance via WSTrust.
277277
* @param {string} wstrustEndpoint An url of an ADFS WSTrust endpoint.
278-
* @param {string} wstrustEndpointVersion The version of the wstrust endpoint.
278+
* @param {string} wstrustEndpointVersion The version of the wstrust endpoint.
279279
* @param {string} username username
280280
* @param {string} password password
281281
* @param {AcquireTokenCallback} callback callback
@@ -379,19 +379,19 @@ TokenRequest.prototype._getTokenUsernamePasswordFederated = function(username, p
379379
* Gets wstrust endpoint version from the federation active auth url.
380380
* @private
381381
* @param {string} federationActiveAuthUrl federationActiveAuthUrl
382-
* @return {object} The wstrust endpoint version.
382+
* @return {object} The wstrust endpoint version.
383383
*/
384384
TokenRequest.prototype._parseWStrustVersionFromFederationActiveAuthUrl = function(federationActiveAuthUrl) {
385385
var wstrust2005Regex = /[/trust]?[2005][/usernamemixed]?/;
386386
var wstrust13Regex = /[/trust]?[13][/usernamemixed]?/;
387-
387+
388388
if (wstrust2005Regex.exec(federationActiveAuthUrl)) {
389389
return WSTrustVersion.WSTRUST2005;
390390
}
391391
else if (wstrust13Regex.exec(federationActiveAuthUrl)) {
392392
return WSTrustVersion.WSTRUST13;
393393
}
394-
394+
395395
return WSTrustVersion.UNDEFINED;
396396
};
397397

@@ -405,10 +405,18 @@ TokenRequest.prototype._parseWStrustVersionFromFederationActiveAuthUrl = functio
405405
*/
406406
TokenRequest.prototype.getTokenWithUsernamePassword = function(username, password, callback) {
407407
this._log.info('Acquiring token with username password');
408-
409408
this._userId = username;
409+
410410
this._getTokenWithCacheWrapper(callback, function(getTokenCompleteCallback) {
411411
var self = this;
412+
413+
if(this._authenticationContext._authority._isAdfsAuthority) {
414+
this._log.info('Skipping user realm discovery for ADFS authority');
415+
416+
self._getTokenUsernamePasswordManaged(username, password, getTokenCompleteCallback);
417+
return;
418+
}
419+
412420
this._userRealm = this._createUserRealmRequest(username);
413421
this._userRealm.discover(function(err) {
414422
if (err) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/AzureAD/azure-activedirectory-library-for-nodejs.git"
1717
},
18-
"version": "0.1.19",
18+
"version": "0.1.20",
1919
"description": "Windows Azure Active Directory Client Library for node",
2020
"keywords": [ "node", "azure", "AAD", "adal", "adfs", "oauth" ],
2121
"main": "./lib/adal.js",

test/username-password.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ suite('username-password', function() {
7979
return util.setupExpectedOAuthResponse(queryParameters, cp.tokenUrlPath, 200, response.wireResponse, cp.authority);
8080
}
8181

82-
function setupExpectedUserNamePasswordRequestResponse(httpCode, returnDoc, authorityEndpoint) {
82+
function setupExpectedUserNamePasswordRequestResponse(httpCode, returnDoc, authorityEndpoint, isAdfs) {
8383
var authEndpoint = util.getNockAuthorityHost(authorityEndpoint);
84-
8584
var queryParameters = {};
8685
queryParameters['grant_type'] = 'password';
8786
queryParameters['client_id'] = cp.clientId;
@@ -91,19 +90,39 @@ suite('username-password', function() {
9190
queryParameters['scope'] = 'openid';
9291

9392
var query = querystring.stringify(queryParameters);
93+
var tokenUrl = cp.tokenUrlPath;
94+
if(isAdfs) {
95+
tokenUrl = '/adfs' + cp.tokenPath + cp.extraQP;
96+
}
9497

9598
var tokenRequest = nock(authEndpoint)
9699
.filteringRequestBody(function(body) {
97100
return util.filterQueryString(query, body);
98101
})
99-
.post(cp.tokenUrlPath, query)
102+
.post(tokenUrl, query)
100103
.reply(httpCode, returnDoc);
101104

102105
util.matchStandardRequestHeaders(tokenRequest);
103106

104107
return tokenRequest;
105108
}
106109

110+
test('happy-path-adfs-authority', function(done) {
111+
var adfsAuthority = "https://contoso.com/adfs";
112+
var responseOptions = { authority : adfsAuthority, mrrt : true };
113+
var response = util.createResponse(responseOptions);
114+
var upRequest = setupExpectedUserNamePasswordRequestResponse(200, response.wireResponse, adfsAuthority, true);
115+
116+
var context = new AuthenticationContext(adfsAuthority, false);
117+
context.acquireTokenWithUsernamePassword(response.resource, cp.username, cp.password, cp.clientId, function(err, tokenResponse) {
118+
if (!err) {
119+
upRequest.done();
120+
assert(util.isMatchTokenResponse(response.cachedResponse, tokenResponse), 'Response did not match expected: ' + JSON.stringify(tokenResponse));
121+
}
122+
done(err);
123+
});
124+
});
125+
107126
test('managed-happy-path', function(done) {
108127
var preRequests = util.setupExpectedUserRealmResponseCommon(false);
109128
var response = util.createResponse();

0 commit comments

Comments
 (0)