From 2645d6c1f475c1a054fd03aa3c676b53ab0a9505 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Tue, 3 Feb 2026 23:56:09 +0100 Subject: [PATCH] Update interactive-login script to use Microsoft Graph API for application retrieval and adjust scopes for Azure Graph --- bin/interactive-login.mjs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/interactive-login.mjs b/bin/interactive-login.mjs index c9bd0e4..a884b23 100755 --- a/bin/interactive-login.mjs +++ b/bin/interactive-login.mjs @@ -3,8 +3,10 @@ import { loginInteractive } from "../src/azure.js"; import { config } from "../public-config.js"; import { createHash } from "crypto"; +import { Client } from "@microsoft/microsoft-graph-client"; -const scopes = ["https://management.azure.com/.default"]; +// const scopes = ["https://management.azure.com/.default"]; +const scopes = ["https://graph.microsoft.com/.default"]; let token; @@ -15,9 +17,9 @@ try { scopes, }); } catch (e) { - console.error("Login failed:", e); - console.error(e.stack); - process.exit(1); + console.error("Login failed:", e); + console.error(e.stack); + process.exit(1); } console.log("Access token acquired."); @@ -26,3 +28,30 @@ console.log("Access token acquired."); const hash = createHash("sha256").update(token.accessToken).digest("hex"); console.log("SHA-256 hash of access token:", hash); console.log("Token expires on:", token.expiresOn); + +const client = Client.init({ + authProvider: (done) => { + done(null, token.accessToken); + }, +}); + +let result; + +result = await client + .api("/applications") + .filter("displayName eq 'Azure Node Playground Public'") + .get(); + +const apps = result.value ?? []; +console.log( + `Registered applications with the name 'Azure Node Playground' (${apps.length}):`, +); + +if (apps.length !== 1) { + console.error( + "Expected exactly one application with the name 'Azure Node Playground'. Please ensure it is registered in your Azure AD tenant.", + ); + process.exit(1); +} + +console.log("Application details:", apps[0]);