Add Microsoft Graph client integration and list applications script protype.
This commit is contained in:
47
bin/list-apps.mjs
Executable file
47
bin/list-apps.mjs
Executable file
@@ -0,0 +1,47 @@
|
||||
#! /usr/bin/env node
|
||||
import { loginInteractive } from "../src/azure.js";
|
||||
import { Client } from "@microsoft/microsoft-graph-client";
|
||||
|
||||
const scopes = [
|
||||
"https://graph.microsoft.com/.default"
|
||||
];
|
||||
const { config } = await import("../public-config.js");
|
||||
|
||||
async function main(config) {
|
||||
const token = await loginInteractive({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
scopes,
|
||||
});
|
||||
console.log("Successfully logged in.");
|
||||
|
||||
const accessToken = token.accessToken;
|
||||
|
||||
const client = Client.init({
|
||||
authProvider: (done) => {
|
||||
done(null, accessToken);
|
||||
},
|
||||
});
|
||||
|
||||
const me = await client
|
||||
.api("/me")
|
||||
.get();
|
||||
|
||||
console.log("User Information:", me);
|
||||
|
||||
const apps = await client
|
||||
.api("/applications")
|
||||
.select("displayName,appId,createdDateTime")
|
||||
.top(50)
|
||||
.get();
|
||||
|
||||
console.log("Applications:");
|
||||
apps.value.forEach((app) => {
|
||||
console.log(`- ${app.displayName} (App ID: ${app.appId}, Created: ${app.createdDateTime})`);
|
||||
});
|
||||
}
|
||||
|
||||
main(config).catch((err) => {
|
||||
console.error("Error in listing applications:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user