48 lines
1.1 KiB
JavaScript
Executable File
48 lines
1.1 KiB
JavaScript
Executable File
#! /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);
|
|
});
|