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);
|
||||
});
|
||||
39
package-lock.json
generated
39
package-lock.json
generated
@@ -9,7 +9,8 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@azure/identity": "^4.13.0",
|
||||
"@azure/msal-node": "^5.0.2"
|
||||
"@azure/msal-node": "^5.0.2",
|
||||
"@microsoft/microsoft-graph-client": "^3.0.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24.0.0"
|
||||
@@ -196,6 +197,42 @@
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/runtime": {
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.6.tgz",
|
||||
"integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/microsoft-graph-client": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/microsoft-graph-client/-/microsoft-graph-client-3.0.7.tgz",
|
||||
"integrity": "sha512-/AazAV/F+HK4LIywF9C+NYHcJo038zEnWkteilcxC1FM/uK/4NVGDKGrxx7nNq1ybspAroRKT4I1FHfxQzxkUw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"tslib": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@azure/identity": {
|
||||
"optional": true
|
||||
},
|
||||
"@azure/msal-browser": {
|
||||
"optional": true
|
||||
},
|
||||
"buffer": {
|
||||
"optional": true
|
||||
},
|
||||
"stream-browserify": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typespec/ts-http-runtime": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@typespec/ts-http-runtime/-/ts-http-runtime-0.3.2.tgz",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@azure/identity": "^4.13.0",
|
||||
"@azure/msal-node": "^5.0.2"
|
||||
"@azure/msal-node": "^5.0.2",
|
||||
"@microsoft/microsoft-graph-client": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user