Moved Graph call prototype using interactive login.
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { loginInteractive } from "sk-az-tools/azure";
|
||||
import { config } from "../public-config.js";
|
||||
import { createHash } from "crypto";
|
||||
import { Client } from "@microsoft/microsoft-graph-client";
|
||||
|
||||
// const scopes = ["https://management.azure.com/.default"];
|
||||
const scopes = ["https://graph.microsoft.com/.default"];
|
||||
|
||||
let token;
|
||||
|
||||
try {
|
||||
token = await loginInteractive({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
scopes,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Login failed:", e);
|
||||
console.error(e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("Access token acquired.");
|
||||
|
||||
// Print SHA-256 hash of the access token for verification purposes
|
||||
const hash = createHash("sha256").update(token.accessToken).digest("hex");
|
||||
console.log("SHA-256 hash of access token:", hash);
|
||||
console.log("Token expires on:", token.expiresOn);
|
||||
|
||||
const client = Client.init({
|
||||
authProvider: (done) => {
|
||||
done(null, token.accessToken);
|
||||
},
|
||||
});
|
||||
|
||||
let result;
|
||||
|
||||
result = await client
|
||||
.api("/applications")
|
||||
.filter("displayName eq 'Azure Node Playground Public'")
|
||||
.get();
|
||||
|
||||
const apps = result.value ?? [];
|
||||
console.log(
|
||||
`Registered applications with the name 'Azure Node Playground' (${apps.length}):`,
|
||||
);
|
||||
|
||||
if (apps.length !== 1) {
|
||||
console.error(
|
||||
"Expected exactly one application with the name 'Azure Node Playground'. Please ensure it is registered in your Azure AD tenant.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
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