Add console-only auth URL option

This commit is contained in:
2026-02-07 09:48:33 +01:00
parent aa75ad11f1
commit e4ffd25379

View File

@@ -53,7 +53,12 @@ async function acquireTokenWithCache({ pca, scopes }) {
return null;
}
export async function loginInteractive({ tenantId, clientId, scopes }) {
export async function loginInteractive({
tenantId,
clientId,
scopes,
showAuthUrlOnly = false,
}) {
if (!tenantId) throw new Error("tenantId is required");
if (!clientId) throw new Error("clientId is required");
if (!Array.isArray(scopes) || scopes.length === 0)
@@ -67,20 +72,27 @@ export async function loginInteractive({ tenantId, clientId, scopes }) {
return await pca.acquireTokenInteractive({
scopes,
openBrowser: async (url) => {
try {
await open(url, { wait: false });
if (showAuthUrlOnly) {
console.log("Visit:\n" + url);
return;
}
// To enforce Microsoft Edge instead of the default browser, use:
// await open(url, {
// return open(url, {
// wait: false,
// app: {
// name: apps.edge,
// },
// }).catch(() => {
// // If auto-open fails, provide URL for manual copy/paste.
// console.log("Visit:\n" + url);
// });
} catch {
return open(url, { wait: false }).catch(() => {
// If auto-open fails, provide URL for manual copy/paste.
console.log("Visit:\n" + url);
});
}
},
});
}