Skip to content

Commit 1d1aed2

Browse files
authored
Adjusted authenticator script to allow running publishing in dev ops. (#2847)
1 parent 6c3bdff commit 1d1aed2

File tree

7 files changed

+49
-160
lines changed

7 files changed

+49
-160
lines changed

auth/arm-auth.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

auth/authenticator.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const {
2+
ClientSecretCredential,
3+
InteractiveBrowserCredential,
4+
} = require("@azure/identity");
5+
6+
// Options may include tenantId and clientId
7+
async function getArmToken(options = {}) {
8+
let credential;
9+
10+
const clientId = options.clientId || process.env.AZURE_CLIENT_ID;
11+
const tenantId = options.tenantId || process.env.AZURE_TENANT_ID;
12+
const clientSecret = options.clientSecret || process.env.AZURE_CLIENT_SECRET;
13+
14+
if (process.env.AZURE_CLIENT_SECRET) {
15+
credential = new ClientSecretCredential(
16+
tenantId,
17+
clientId,
18+
clientSecret
19+
);
20+
} else {
21+
// Use interactive browser authentication (developer/manual mode)
22+
credential = new InteractiveBrowserCredential({
23+
tenantId: tenantId,
24+
clientId: clientId,
25+
loginStyle: "popup",
26+
});
27+
console.log("Please sign in via the browser window that will open...");
28+
}
29+
30+
// Request ARM token for the Management API
31+
const scope = "https://management.azure.com/.default";
32+
const response = await credential.getToken(scope);
33+
34+
if (response && response.token) {
35+
console.log(
36+
"Successfully acquired token with expiration at",
37+
response.expiresOnTimestamp
38+
? new Date(response.expiresOnTimestamp).toLocaleString()
39+
: "unknown"
40+
);
41+
return `${response.tokenType} ${response.token}`; // Returns the actual token string
42+
} else {
43+
throw new Error("Failed to acquire token. Empty response.");
44+
}
45+
}
46+
47+
module.exports = getArmToken;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"test": "node node_modules/mocha/bin/_mocha -r mocha.js src/**/*.spec.ts",
2121
"deploy-function": "npm run build-function && cd dist/function && func azure functionapp publish < function app name >",
2222
"publish": "webpack --config webpack.publisher.js && node dist/publisher/index.js && npm run serve-website",
23-
"publish-arm": "webpack --config webpack.publisher.arm.js && node dist/publisher/index.js && npm run serve-website",
2423
"serve-website": "webpack serve --open --static ./dist/website --no-stats",
2524
"build-mock-static-data": "webpack --config webpack.mockStaticData.js && node dist/publisher/index.js",
2625
"build-static-data": "webpack --config webpack.staticData.js && node dist/publisher/index.js",

src/config.publish.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"environment": "publishing",
3-
"isArmAuthEnabled": true,
43
"subscriptionId": "< subscription ID >",
54
"resourceGroupName": "< resource group name >",
65
"serviceName": "< service name >"

webpack.develop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
designerConfig,
55
designerRuntimeConfig,
66
} = require("./webpack.designer.js");
7-
const { getArmToken } = require("./auth/arm-auth");
7+
const getArmToken = require("./auth/authenticator");
88

99
module.exports = async (env) => {
1010
const armToken = await getArmToken({});

webpack.publisher.arm.js

Lines changed: 0 additions & 115 deletions
This file was deleted.

webpack.publisher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { merge } = require("webpack-merge");
44
const CopyWebpackPlugin = require("copy-webpack-plugin");
55
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
66
const runtimeConfig = require("./webpack.runtime");
7-
const { getArmToken } = require("./auth/arm-auth");
7+
const getArmToken = require("./auth/authenticator");
88
const config = require("./src/config.publish.json");
99

1010
const publisherRuntimeConfig = merge(runtimeConfig, {

0 commit comments

Comments
 (0)