Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amarzavery committed Sep 29, 2017
1 parent b9af146 commit 91543a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 4 additions & 1 deletion runtime/ms-rest-azure/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### 2.3.4 (09/22/2017)
### 2.3.5 (09/29/2017)
- Added retry logic for interactiveLogin if 'authorization_pending' error is received as pointed in issue #2002.

### 2.3.4 (09/29/2017)
- Updated version of dependencies like async, uuid and moment.

### 2.3.3 (09/22/2017)
Expand Down
28 changes: 20 additions & 8 deletions runtime/ms-rest-azure/lib/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ function _interactive(options, callback) {
let authorityUrl = interactiveOptions.environment.activeDirectoryEndpointUrl + interactiveOptions.domain;
interactiveOptions.context = new adal.AuthenticationContext(authorityUrl, interactiveOptions.environment.validateAuthority, interactiveOptions.tokenCache);
let tenantList = [];
// will retry until a non-pending error is returned or credentials are returned.
let tryAcquireToken = function (userCodeResponse, callback) {
interactiveOptions.context.acquireTokenWithDeviceCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, userCodeResponse, function (err, tokenResponse) {
if (err) {
if (err.error === 'authorization_pending') {
setTimeout(() => {
tryAcquireToken(userCodeResponse, callback);
}, 1000);
} else {
return callback(err);
}
}
interactiveOptions.username = tokenResponse.userId;
interactiveOptions.authorizationScheme = tokenResponse.tokenType;
return callback(null);
});
};

//execute actions in sequence
async.waterfall([
//acquire usercode
function (callback) {
Expand All @@ -185,14 +204,7 @@ function _interactive(options, callback) {
});
},
//acquire token with device code and set the username to userId received from tokenResponse.
function (userCodeResponse, callback) {
interactiveOptions.context.acquireTokenWithDeviceCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, userCodeResponse, function (err, tokenResponse) {
if (err) return callback(err);
interactiveOptions.username = tokenResponse.userId;
interactiveOptions.authorizationScheme = tokenResponse.tokenType;
return callback(null);
});
},
tryAcquireToken,
//get the list of tenants
function (callback) {
let credentials = _createCredentials.call(interactiveOptions);
Expand Down
2 changes: 1 addition & 1 deletion runtime/ms-rest-azure/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/ms-rest-azure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "[email protected]",
"url": "https://github.com/Azure/azure-sdk-for-node"
},
"version": "2.3.4",
"version": "2.3.5",
"description": "Client Runtime for Node.js Azure client libraries generated using AutoRest",
"tags": [
"node",
Expand Down

0 comments on commit 91543a5

Please sign in to comment.