feat(cli): add graph commands with query and table output
This commit is contained in:
@@ -30,3 +30,88 @@ export async function createApp(client, displayName) {
|
||||
export async function deleteApp(client, appObjectId) {
|
||||
await client.api(`/applications/${appObjectId}`).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* List Azure applications, optionally filtered by display name.
|
||||
*
|
||||
* @param { Object } client
|
||||
* @param { Object } [options]
|
||||
* @param { string } [options.displayName]
|
||||
* @returns { Promise<Array> }
|
||||
*/
|
||||
export async function listApps(client, options = {}) {
|
||||
const { displayName } = options;
|
||||
let request = client.api("/applications");
|
||||
|
||||
if (displayName) {
|
||||
request = request.filter(`displayName eq '${displayName}'`);
|
||||
}
|
||||
|
||||
const result = await request.get();
|
||||
return Array.isArray(result?.value) ? result.value : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* List required resource access configuration for an application by appId.
|
||||
*
|
||||
* @param { Object } client
|
||||
* @param { string } appId
|
||||
* @returns { Promise<Array> }
|
||||
*/
|
||||
export async function listAppPermissions(client, appId) {
|
||||
if (!appId) {
|
||||
throw new Error("appId is required");
|
||||
}
|
||||
|
||||
const result = await client
|
||||
.api("/applications")
|
||||
.filter(`appId eq '${appId}'`)
|
||||
.select("id,appId,displayName,requiredResourceAccess")
|
||||
.get();
|
||||
|
||||
const app = Array.isArray(result?.value) && result.value.length > 0
|
||||
? result.value[0]
|
||||
: null;
|
||||
|
||||
if (!app) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(app.requiredResourceAccess)
|
||||
? app.requiredResourceAccess
|
||||
: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* List delegated OAuth2 permission grants for an application by appId.
|
||||
*
|
||||
* @param { Object } client
|
||||
* @param { string } appId
|
||||
* @returns { Promise<Array> }
|
||||
*/
|
||||
export async function listAppGrants(client, appId) {
|
||||
if (!appId) {
|
||||
throw new Error("appId is required");
|
||||
}
|
||||
|
||||
const spResult = await client
|
||||
.api("/servicePrincipals")
|
||||
.filter(`appId eq '${appId}'`)
|
||||
.select("id,appId,displayName")
|
||||
.get();
|
||||
|
||||
const servicePrincipal = Array.isArray(spResult?.value) && spResult.value.length > 0
|
||||
? spResult.value[0]
|
||||
: null;
|
||||
|
||||
if (!servicePrincipal?.id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const grantsResult = await client
|
||||
.api("/oauth2PermissionGrants")
|
||||
.filter(`clientId eq '${servicePrincipal.id}'`)
|
||||
.get();
|
||||
|
||||
return Array.isArray(grantsResult?.value) ? grantsResult.value : [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user