UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

52 lines 2.52 kB
import config from '../../../../config.js'; import request from '../../../../request.js'; import { spo } from '../../../../utils/spo.js'; import SpoCommand from '../../../base/SpoCommand.js'; import commands from '../../commands.js'; class SpoServicePrincipalGrantListCommand extends SpoCommand { get name() { return commands.SERVICEPRINCIPAL_GRANT_LIST; } get description() { return 'Lists permissions granted to the service principal'; } alias() { return [commands.SP_GRANT_LIST]; } async commandAction(logger) { try { const spoAdminUrl = await spo.getSpoAdminUrl(logger, this.debug); if (this.verbose) { await logger.logToStderr(`Retrieving request digest...`); } const reqDigest = await spo.getRequestDigest(spoAdminUrl); const requestOptions = { url: `${spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`, headers: { 'X-RequestDigest': reqDigest.FormDigestValue }, data: `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="4" ObjectPathId="3" /><ObjectPath Id="6" ObjectPathId="5" /><Query Id="7" ObjectPathId="5"><Query SelectAllProperties="true"><Properties /></Query><ChildItemQuery SelectAllProperties="true"><Properties /></ChildItemQuery></Query></Actions><ObjectPaths><Constructor Id="3" TypeId="{104e8f06-1e00-4675-99c6-1b9b504ed8d8}" /><Property Id="5" ParentId="3" Name="PermissionGrants" /></ObjectPaths></Request>` }; const res = await request.post(requestOptions); const json = JSON.parse(res); const response = json[0]; if (response.ErrorInfo) { throw response.ErrorInfo.ErrorMessage; } else { const result = json[json.length - 1]._Child_Items_; await logger.log(result.map(r => { delete r._ObjectType_; delete r.ClientId; delete r.ConsentType; return r; })); } } catch (err) { this.handleRejectedPromise(err); } } } export default new SpoServicePrincipalGrantListCommand(); //# sourceMappingURL=serviceprincipal-grant-list.js.map