Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit fec0b11

Browse files
committed
domain is not a required parameter
1 parent 8574c83 commit fec0b11

File tree

7 files changed

+20
-36
lines changed

7 files changed

+20
-36
lines changed

runtime/ms-rest-azure/Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 2.3.3 (09/22/2017)
2+
- With latest changes in the service code, domain is no more a required parameter for MSITokenCredentials.
3+
14
### 2.3.2 (09/21/2017)
25
- Fixed bugs in index.d.ts related to MSITokenCredentials and loginWithMSI method
36
- Fixed bugs in the MSITokenCredentials class

runtime/ms-rest-azure/index.d.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,9 @@ export class MSITokenCredentials {
508508
* This method makes a request to the authentication service hosted on the VM
509509
* and gets back an access token.
510510
*
511-
* @param {string} domain - The domain or tenant id. This is a required parameter.
512511
* @param {MSIOptions} [options] - Optional parameters.
513512
*/
514-
constructor(domain: string, options?: MSIOptions);
513+
constructor(options?: MSIOptions);
515514
/**
516515
* Prepares and sends a POST request to a service endpoint hosted on the Azure VM, which responds with the access token.
517516
* @param {function} callback The callback in the form (err, result)
@@ -764,7 +763,6 @@ export interface MSIOptions {
764763
* This method makes a request to the authentication service hosted on the VM
765764
* and gets back an access token.
766765
*
767-
* @param {string} domain - The domain or tenant id. This is a required parameter.
768766
* @param {object} [options] - Optional parameters
769767
* @param {string} [options.port] - port on which the MSI service is running on the host VM. Default port is 50342
770768
* @param {string} [options.resource] - The resource uri or token audience for which the token is needed.
@@ -782,6 +780,6 @@ export interface MSIOptions {
782780
* @resolve {object} - tokenResponse.
783781
* @reject {Error} - error object.
784782
*/
785-
export function loginWithMSI(domain: string, callback: { (err: Error, credentials: MSITokenCredentials): void }): void;
786-
export function loginWithMSI(domain: string, options: MSIOptions, callback: { (err: Error, credentials: MSITokenCredentials): void }): void;
787-
export function loginWithMSI(domain: string, options?: MSIOptions): Promise<MSITokenCredentials>;
783+
export function loginWithMSI(callback: { (err: Error, credentials: MSITokenCredentials): void }): void;
784+
export function loginWithMSI(options: MSIOptions, callback: { (err: Error, credentials: MSITokenCredentials): void }): void;
785+
export function loginWithMSI(options?: MSIOptions): Promise<MSITokenCredentials>;

runtime/ms-rest-azure/lib/credentials/msiTokenCredentials.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ const request = require('request');
1313
const Constants = msrest.Constants;
1414

1515
class MSITokenCredentials {
16-
constructor(domain, options) {
17-
18-
if (!Boolean(domain) || typeof domain.valueOf() !== 'string') {
19-
throw new Error('domain must be a non empty string.');
20-
}
21-
16+
constructor(options) {
2217
if (!options) {
2318
options = {};
2419
}
@@ -34,11 +29,9 @@ class MSITokenCredentials {
3429
} else if (typeof options.resource.valueOf() !== 'string') {
3530
throw new Error('resource must be a uri.');
3631
}
37-
38-
this.domain = domain;
32+
3933
this.port = options.port;
4034
this.resource = options.resource;
41-
this.aadEndpoint = 'https://login.microsoftonline.com';
4235
}
4336

4437
/**
@@ -72,7 +65,6 @@ class MSITokenCredentials {
7265

7366
prepareRequestOptions() {
7467
const resource = encodeURIComponent(this.resource);
75-
const aadEndpoint = encodeURIComponent(this.aadEndpoint);
7668
const forwardSlash = encodeURIComponent('/');
7769
let reqOptions = {
7870
headers: {},

runtime/ms-rest-azure/lib/login.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -699,18 +699,17 @@ exports.withAuthFileWithAuthResponse = function withAuthFileWithAuthResponse(opt
699699

700700
/**
701701
* private helper for MSI auth. Initializes MSITokenCredentials class and calls getToken and returns a token response.
702-
*
703-
* @param {string} domain -- required. The tenant id.
702+
*
704703
* @param {object} options -- Optional parameters
705704
* @param {string} [options.port] - port on which the MSI service is running on the host VM. Default port is 50342
706705
* @param {string} [options.resource] - The resource uri or token audience for which the token is needed.
707706
* @param {any} callback - the callback function.
708707
*/
709-
function _withMSI(domain, options, callback) {
708+
function _withMSI(options, callback) {
710709
if (!callback) {
711710
throw new Error('callback cannot be null or undefined.');
712711
}
713-
const creds = new MSITokenCredentials(domain, options);
712+
const creds = new MSITokenCredentials(options);
714713
creds.getToken(function (err) {
715714
if (err) return callback(err);
716715
return callback(null, creds);
@@ -736,7 +735,6 @@ function _withMSI(domain, options, callback) {
736735
* This method makes a request to the authentication service hosted on the VM
737736
* and gets back an access token.
738737
*
739-
* @param {string} domain - The domain or tenant id. This is a required parameter.
740738
* @param {object} [options] - Optional parameters
741739
* @param {string} [options.port] - port on which the MSI service is running on the host VM. Default port is 50342
742740
* @param {string} [options.resource] - The resource uri or token audience for which the token is needed.
@@ -754,17 +752,14 @@ function _withMSI(domain, options, callback) {
754752
* @resolve {object} - tokenResponse.
755753
* @reject {Error} - error object.
756754
*/
757-
exports.withMSI = function withMSI(domain, options, optionalCallback) {
758-
if (!Boolean(domain) || typeof domain.valueOf() !== 'string') {
759-
throw new Error('domain must be a non empty string.');
760-
}
755+
exports.withMSI = function withMSI(options, optionalCallback) {
761756
if (!optionalCallback && typeof options === 'function') {
762757
optionalCallback = options;
763758
options = {};
764759
}
765760
if (!optionalCallback) {
766761
return new Promise((resolve, reject) => {
767-
_withMSI(domain, options, (err, credentials) => {
762+
_withMSI(options, (err, credentials) => {
768763
if (err) { reject(err); }
769764
else { resolve(credentials); }
770765
return;

runtime/ms-rest-azure/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/ms-rest-azure/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"email": "[email protected]",
66
"url": "https://github.com/Azure/azure-sdk-for-node"
77
},
8-
"version": "2.3.2",
8+
"version": "2.3.3",
99
"description": "Client Runtime for Node.js Azure client libraries generated using AutoRest",
1010
"tags": [
1111
"node",

runtime/ms-rest-azure/test/msiTokenCredentialTests.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ describe('MSI Authentication', function () {
6464
};
6565

6666
let requestBodyToMatch = {
67-
"authority": "https://login.microsoftonline.com/5485482-38d2-4bad-bad9-b7b93a3eb7b9",
6867
"resource": "https://management.azure.com/"
6968
};
7069

7170
setupNockResponse(null, requestBodyToMatch, response);
7271

73-
let msiCredsObj = new MSITokenCredential("5485482-38d2-4bad-bad9-b7b93a3eb7b9");
72+
let msiCredsObj = new MSITokenCredential();
7473
msiCredsObj.getToken((err, response) => {
7574
should.not.exist(err);
7675
should.exist(response);
@@ -92,14 +91,13 @@ describe('MSI Authentication', function () {
9291
};
9392

9493
let requestBodyToMatch = {
95-
"authority": "https://login.microsoftonline.com/5485482-38d2-4bad-bad9-b7b93a3eb7b9",
9694
"resource": "https://management.azure.com/"
9795
};
9896

9997
let customPort = 50341;
10098
setupNockResponse(customPort, requestBodyToMatch, response);
10199

102-
let msiCredsObj = new MSITokenCredential("5485482-38d2-4bad-bad9-b7b93a3eb7b9", { port: customPort });
100+
let msiCredsObj = new MSITokenCredential({ port: customPort });
103101
msiCredsObj.getToken((err, response) => {
104102
should.not.exist(err);
105103
should.exist(response);
@@ -116,13 +114,12 @@ describe('MSI Authentication', function () {
116114
};
117115

118116
let requestBodyToMatch = {
119-
"authority": "https://login.microsoftonline.com/5485482-38d2-4bad-bad9-b7b93a3eb7b9",
120117
"resource": "badvalue"
121118
};
122119

123120
setupNockResponse(null, requestBodyToMatch, null, errorResponse);
124121

125-
let msiCredsObj = new MSITokenCredential("5485482-38d2-4bad-bad9-b7b93a3eb7b9", { "resource": "badvalue" });
122+
let msiCredsObj = new MSITokenCredential({ "resource": "badvalue" });
126123
msiCredsObj.getToken((err, response) => {
127124
should.exist(err);
128125
should.not.exist(response);
@@ -134,13 +131,12 @@ describe('MSI Authentication', function () {
134131
let errorResponse = { "error": "bad_resource_200", "error_description": "Invalid Resource" };
135132

136133
let requestBodyToMatch = {
137-
"authority": "https://login.microsoftonline.com/5485482-38d2-4bad-bad9-b7b93a3eb7b9",
138134
"resource": " "
139135
};
140136

141137
setupNockResponse(null, requestBodyToMatch, null, errorResponse);
142138

143-
let msiCredsObj = new MSITokenCredential("5485482-38d2-4bad-bad9-b7b93a3eb7b9", { "resource": " " });
139+
let msiCredsObj = new MSITokenCredential({ "resource": " " });
144140
msiCredsObj.getToken((err, response) => {
145141
should.exist(err);
146142
should.equal(err.error, "bad_resource_200");

0 commit comments

Comments
 (0)