Skip to content

Commit 2a8c31e

Browse files
authored
Migrate editor and publisher to ARM (#2792)
Migrated editor, publisher to ARM auth Migrated runtime to Data API Migrated unit tests to Data API Migrated static data with new portal config data to Data API Migrated e2e tests to Data API
1 parent 119c314 commit 2a8c31e

File tree

272 files changed

+12800
-15183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+12800
-15183
lines changed

auth/arm-auth.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { InteractiveBrowserCredential } = require('@azure/identity');
2+
3+
/**
4+
* Gets authentication ARM token using interactive browser authentication
5+
* @param {Object} options - Configuration options
6+
* @param {string} [options.tenantId] - Optional tenant ID to override default tenant
7+
* @param {string} [options.clientId] - Optional client ID for the application
8+
* @param {string} [options.redirectUri] - Optional redirect URI for the authentication flow
9+
* @returns {Promise<string>} - Bearer token for portal.azure.com
10+
*/
11+
async function getArmToken(options = {}) {
12+
try {
13+
const credential = new InteractiveBrowserCredential({
14+
tenantId: options.tenantId,
15+
clientId: options.clientId,
16+
redirectUri: options.redirectUri || 'http://localhost:8080'
17+
});
18+
19+
const scope = "https://management.azure.com/user_impersonation";
20+
21+
console.log("Please sign in via the browser window that will open...");
22+
23+
// Get the token - this will open a browser window for authentication
24+
const response = await credential.getToken(scope);
25+
26+
if (response && response.token) {
27+
console.log("Successfully acquired token with expiration at:", (new Date(response.expiresOnTimestamp)).toLocaleString());
28+
return `Bearer ${response.token}`;
29+
} else {
30+
throw new Error("Failed to acquire token: Empty response");
31+
}
32+
} catch (error) {
33+
console.error("Error acquiring portal token:", error.message);
34+
throw error;
35+
}
36+
}
37+
38+
module.exports = {
39+
getArmToken
40+
};

0 commit comments

Comments
 (0)