UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

46 lines 2.02 kB
import { odata } from './odata.js'; import { formatting } from './formatting.js'; import { cli } from '../cli/cli.js'; export const entraServicePrincipal = { /** * Get service principal by its appId * @param appId App id. * @param properties Comma-separated list of properties to include in the response. * @returns The service principal. * @throws Error when service principal was not found. */ async getServicePrincipalByAppId(appId, properties) { let url = `https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '${appId}'`; if (properties) { url += `&$select=${properties}`; } const apps = await odata.getAllItems(url); if (apps.length === 0) { throw `Service principal with appId '${appId}' not found in Microsoft Entra ID`; } return apps[0]; }, /** * Get service principal by its name * @param appName Service principal name. * @param properties Comma-separated list of properties to include in the response. * @returns The service principal. * @throws Error when service principal was not found. */ async getServicePrincipalByAppName(appName, properties) { let url = `https://graph.microsoft.com/v1.0/servicePrincipals?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'`; if (properties) { url += `&$select=${properties}`; } const apps = await odata.getAllItems(url); if (apps.length === 0) { throw `Service principal with name '${appName}' not found in Microsoft Entra ID`; } if (apps.length > 1) { const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps); return await cli.handleMultipleResultsFound(`Multiple service principals with name '${appName}' found in Microsoft Entra ID.`, resultAsKeyValuePair); } return apps[0]; } }; //# sourceMappingURL=entraServicePrincipal.js.map