Refactor interactive-login script to import loginInteractive from sk-az-tools and enhance service principal retrieval
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { loginInteractive } from "../src/azure.js";
|
import { loginInteractive } from "sk-az-tools/azure";
|
||||||
import { config } from "../public-config.js";
|
import { config } from "../public-config.js";
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
import { Client } from "@microsoft/microsoft-graph-client";
|
import { Client } from "@microsoft/microsoft-graph-client";
|
||||||
@@ -54,4 +54,29 @@ if (apps.length !== 1) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Application details:", apps[0]);
|
console.log(`Application ID: ${apps[0].appId}`);
|
||||||
|
|
||||||
|
// Let's find the service principals for this application
|
||||||
|
result = await client
|
||||||
|
.api("/servicePrincipals")
|
||||||
|
.filter(`appId eq '${apps[0].appId}'`)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const sps = result.value ?? [];
|
||||||
|
console.log(
|
||||||
|
`Service principals for the application (${sps.length}):`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sps.length === 0) {
|
||||||
|
console.error(
|
||||||
|
"No service principals found for the application. Please ensure the application is properly configured in your Azure AD tenant.",
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sps.forEach((sp, index) => {
|
||||||
|
console.log(`Service Principal ${index + 1}:`);
|
||||||
|
console.log(` ID: ${sp.id}`);
|
||||||
|
console.log(` App ID: ${sp.appId}`);
|
||||||
|
console.log(` Display Name: ${sp.displayName}`);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user