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