Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
91 lines
3.4 KiB
JavaScript
Executable File
91 lines
3.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Lists Microsoft Graph change notification subscriptions using app credentials
|
|
// Reads credentials from environment variables:
|
|
// - MICROSOFT_TENANT_ID
|
|
// - MICROSOFT_CLIENT_ID
|
|
// - MICROSOFT_CLIENT_SECRET
|
|
|
|
import axios from 'axios';
|
|
|
|
async function main() {
|
|
const tenantId = process.env.MICROSOFT_TENANT_ID;
|
|
const clientId = process.env.MICROSOFT_CLIENT_ID;
|
|
const clientSecret = process.env.MICROSOFT_CLIENT_SECRET;
|
|
const refreshToken = process.env.MICROSOFT_REFRESH_TOKEN;
|
|
const accessTokenEnv = process.env.MICROSOFT_ACCESS_TOKEN;
|
|
const redirectUri = process.env.MICROSOFT_REDIRECT_URI;
|
|
|
|
if (!tenantId || !clientId || !clientSecret) {
|
|
console.error('Missing required env vars: MICROSOFT_TENANT_ID, MICROSOFT_CLIENT_ID, MICROSOFT_CLIENT_SECRET');
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
const tokenUrl = `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/token`;
|
|
let accessToken;
|
|
if (accessTokenEnv) {
|
|
console.log('Using provided MICROSOFT_ACCESS_TOKEN');
|
|
accessToken = accessTokenEnv;
|
|
} else if (refreshToken) {
|
|
const params = new URLSearchParams({
|
|
client_id: clientId,
|
|
client_secret: clientSecret,
|
|
grant_type: 'refresh_token',
|
|
refresh_token: refreshToken,
|
|
redirect_uri: redirectUri || 'https://localhost/unused',
|
|
scope: 'https://graph.microsoft.com/.default offline_access'
|
|
});
|
|
process.stdout.write('Refreshing delegated access token... ');
|
|
const resp = await axios.post(tokenUrl, params.toString(), {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
});
|
|
console.log('OK');
|
|
accessToken = resp.data.access_token;
|
|
} else {
|
|
const tokenParams = new URLSearchParams({
|
|
client_id: clientId,
|
|
client_secret: clientSecret,
|
|
grant_type: 'client_credentials',
|
|
scope: 'https://graph.microsoft.com/.default'
|
|
});
|
|
process.stdout.write('Requesting app token... ');
|
|
const tokenResp = await axios.post(tokenUrl, tokenParams.toString(), {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
});
|
|
console.log('OK');
|
|
accessToken = tokenResp.data.access_token;
|
|
}
|
|
const graph = axios.create({
|
|
baseURL: 'https://graph.microsoft.com/v1.0',
|
|
headers: { Authorization: `Bearer ${accessToken}` }
|
|
});
|
|
|
|
process.stdout.write('Listing subscriptions... ');
|
|
const subsResp = await graph.get('/subscriptions');
|
|
console.log('OK');
|
|
|
|
const subs = subsResp.data?.value || [];
|
|
if (!subs.length) {
|
|
console.log('\nNo subscriptions found for this app identity.');
|
|
console.log('Note: App-only listing only shows subscriptions created by this same app identity.');
|
|
} else {
|
|
console.log(`\nFound ${subs.length} subscription(s):\n`);
|
|
subs.forEach((s, idx) => {
|
|
console.log(`#${idx + 1}`);
|
|
console.log(` id: ${s.id}`);
|
|
console.log(` resource: ${s.resource}`);
|
|
console.log(` notificationUrl: ${s.notificationUrl}`);
|
|
console.log(` expirationDateTime: ${s.expirationDateTime}`);
|
|
console.log(` clientState: ${s.clientState || ''}`);
|
|
console.log('');
|
|
});
|
|
}
|
|
} catch (err) {
|
|
const detail = err?.response?.data || err?.message || err;
|
|
console.error('\nFailed:', typeof detail === 'string' ? detail : JSON.stringify(detail, null, 2));
|
|
process.exit(2);
|
|
}
|
|
}
|
|
|
|
main();
|