Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions auth/arm-auth.js

This file was deleted.

47 changes: 47 additions & 0 deletions auth/authenticator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const {
ClientSecretCredential,
InteractiveBrowserCredential,
} = require("@azure/identity");

// Options may include tenantId and clientId
async function getArmToken(options = {}) {
let credential;

const clientId = options.clientId || process.env.AZURE_CLIENT_ID;
const tenantId = options.tenantId || process.env.AZURE_TENANT_ID;
const clientSecret = options.clientSecret || process.env.AZURE_CLIENT_SECRET;

if (process.env.AZURE_CLIENT_SECRET) {
credential = new ClientSecretCredential(
tenantId,
clientId,
clientSecret
);
} else {
// Use interactive browser authentication (developer/manual mode)
credential = new InteractiveBrowserCredential({
tenantId: tenantId,
clientId: clientId,
loginStyle: "popup",
});
console.log("Please sign in via the browser window that will open...");
}

// Request ARM token for the Management API
const scope = "https://management.azure.com/.default";
const response = await credential.getToken(scope);

if (response && response.token) {
console.log(
"Successfully acquired token with expiration at",
response.expiresOnTimestamp
? new Date(response.expiresOnTimestamp).toLocaleString()
: "unknown"
);
return `${response.tokenType} ${response.token}`; // Returns the actual token string
} else {
throw new Error("Failed to acquire token. Empty response.");
}
}

module.exports = getArmToken;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"test": "node node_modules/mocha/bin/_mocha -r mocha.js src/**/*.spec.ts",
"deploy-function": "npm run build-function && cd dist/function && func azure functionapp publish < function app name >",
"publish": "webpack --config webpack.publisher.js && node dist/publisher/index.js && npm run serve-website",
"publish-arm": "webpack --config webpack.publisher.arm.js && node dist/publisher/index.js && npm run serve-website",
"serve-website": "webpack serve --open --static ./dist/website --no-stats",
"build-mock-static-data": "webpack --config webpack.mockStaticData.js && node dist/publisher/index.js",
"build-static-data": "webpack --config webpack.staticData.js && node dist/publisher/index.js",
Expand Down
1 change: 0 additions & 1 deletion src/config.publish.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"environment": "publishing",
"isArmAuthEnabled": true,
"subscriptionId": "< subscription ID >",
"resourceGroupName": "< resource group name >",
"serviceName": "< service name >"
Expand Down
2 changes: 1 addition & 1 deletion webpack.develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
designerConfig,
designerRuntimeConfig,
} = require("./webpack.designer.js");
const { getArmToken } = require("./auth/arm-auth");
const getArmToken = require("./auth/authenticator");

module.exports = async (env) => {
const armToken = await getArmToken({});
Expand Down
115 changes: 0 additions & 115 deletions webpack.publisher.arm.js

This file was deleted.

2 changes: 1 addition & 1 deletion webpack.publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { merge } = require("webpack-merge");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const runtimeConfig = require("./webpack.runtime");
const { getArmToken } = require("./auth/arm-auth");
const getArmToken = require("./auth/authenticator");
const config = require("./src/config.publish.json");

const publisherRuntimeConfig = merge(runtimeConfig, {
Expand Down
Loading