diff --git a/src/azure/pca-auth.js b/src/azure/pca-auth.js index d39e9ba..5bb764f 100644 --- a/src/azure/pca-auth.js +++ b/src/azure/pca-auth.js @@ -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 }); - // To enforce Microsoft Edge instead of the default browser, use: - // await open(url, { - // wait: false, - // app: { - // name: apps.edge, - // }, - // }); - } catch { + if (showAuthUrlOnly) { + console.log("Visit:\n" + url); + return; + } + + // To enforce Microsoft Edge instead of the default browser, use: + // 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); + // }); + + return open(url, { wait: false }).catch(() => { // If auto-open fails, provide URL for manual copy/paste. console.log("Visit:\n" + url); - } - }, + }); + } }); }