Add console-only auth URL option
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user