@pnp/cli-microsoft365 9.0.0-beta.e69e8d0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/allCommands.json +1 -1
- package/allCommandsFull.json +1 -1
- package/dist/Auth.js +11 -12
- package/dist/Command.js +1 -3
- package/dist/cli/cli.js +68 -14
- package/dist/config.js +60 -5
- package/dist/m365/app/commands/permission/permission-add.js +9 -9
- package/dist/m365/base/SpoCommand.js +1 -1
- package/dist/m365/cli/commands/cli-consent.js +2 -2
- package/dist/m365/cli/commands/cli-doctor.js +2 -2
- package/dist/m365/cli/commands/cli-reconsent.js +2 -3
- package/dist/m365/cli/commands/config/config-set.js +12 -3
- package/dist/m365/commands/login.js +38 -14
- package/dist/m365/commands/setup.js +256 -33
- package/dist/m365/commands/status.js +2 -2
- package/dist/m365/connection/commands/connection-list.js +4 -4
- package/dist/m365/entra/commands/app/app-add.js +52 -288
- package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-add.js +13 -13
- package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-get.js +18 -18
- package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-list.js +1 -1
- package/dist/m365/entra/commands/enterpriseapp/enterpriseapp-remove.js +123 -0
- package/dist/m365/entra/commands/group/group-set.js +256 -0
- package/dist/m365/entra/commands/group/group-user-list.js +4 -4
- package/dist/m365/entra/commands/m365group/m365group-conversation-post-list.js +4 -4
- package/dist/m365/entra/commands/m365group/m365group-recyclebinitem-list.js +3 -3
- package/dist/m365/entra/commands/m365group/m365group-user-list.js +9 -6
- package/dist/m365/entra/commands.js +3 -0
- package/dist/m365/onenote/commands/notebook/notebook-add.js +132 -0
- package/dist/m365/onenote/commands.js +1 -0
- package/dist/m365/outlook/commands/message/message-get.js +11 -11
- package/dist/m365/spfx/commands/project/DeployWorkflow.js +1 -1
- package/dist/m365/spfx/commands/project/project-github-workflow-add.js +10 -1
- package/dist/m365/spo/commands/file/file-copy.js +34 -55
- package/dist/m365/spo/commands/folder/folder-set.js +4 -0
- package/dist/m365/spo/commands/list/list-list.js +4 -1
- package/dist/m365/spo/commands/site/site-appcatalog-remove.js +24 -48
- package/dist/m365/spo/commands/site/site-get.js +12 -16
- package/dist/m365/spo/commands/site/site-remove.js +7 -1
- package/dist/m365/spo/commands/tenant/tenant-recyclebinitem-restore.js +22 -2
- package/dist/m365/spo/commands.js +1 -0
- package/dist/m365/teams/commands/message/message-restore.js +106 -0
- package/dist/m365/teams/commands.js +1 -0
- package/dist/settingsNames.js +7 -1
- package/dist/utils/entraApp.js +283 -0
- package/dist/utils/spo.js +0 -74
- package/docs/docs/_clisettings.mdx +6 -0
- package/docs/docs/cmd/app/permission/permission-add.mdx +5 -5
- package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-add.mdx +12 -12
- package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-get.mdx +14 -14
- package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-list.mdx +5 -5
- package/docs/docs/cmd/entra/enterpriseapp/enterpriseapp-remove.mdx +65 -0
- package/docs/docs/cmd/entra/group/group-add.mdx +0 -4
- package/docs/docs/cmd/entra/group/group-set.mdx +89 -0
- package/docs/docs/cmd/entra/group/group-user-list.mdx +7 -7
- package/docs/docs/cmd/entra/m365group/m365group-conversation-post-list.mdx +5 -5
- package/docs/docs/cmd/entra/m365group/m365group-recyclebinitem-list.mdx +3 -3
- package/docs/docs/cmd/entra/m365group/m365group-user-list.mdx +1 -1
- package/docs/docs/cmd/onenote/notebook/notebook-add.mdx +169 -0
- package/docs/docs/cmd/outlook/message/message-get.mdx +5 -5
- package/docs/docs/cmd/setup.mdx +16 -3
- package/docs/docs/cmd/spfx/project/project-github-workflow-add.mdx +12 -11
- package/docs/docs/cmd/spo/file/file-copy.mdx +12 -119
- package/docs/docs/cmd/spo/folder/folder-set.mdx +6 -0
- package/docs/docs/cmd/spo/list/list-list.mdx +7 -5
- package/docs/docs/cmd/spo/site/site-appcatalog-remove.mdx +2 -11
- package/docs/docs/cmd/spo/site/site-remove.mdx +3 -0
- package/docs/docs/cmd/spo/tenant/tenant-recyclebinitem-restore.mdx +49 -2
- package/docs/docs/cmd/teams/message/message-remove.mdx +2 -1
- package/docs/docs/cmd/teams/message/message-restore.mdx +62 -0
- package/npm-shrinkwrap.json +0 -1
- package/package.json +2 -3
|
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _SpoTenantRecycleBinItemRestoreCommand_instances, _SpoTenantRecycleBinItemRestoreCommand_initOptions, _SpoTenantRecycleBinItemRestoreCommand_initValidators, _SpoTenantRecycleBinItemRestoreCommand_initTypes;
|
|
6
|
+
var _SpoTenantRecycleBinItemRestoreCommand_instances, _SpoTenantRecycleBinItemRestoreCommand_initTelemetry, _SpoTenantRecycleBinItemRestoreCommand_initOptions, _SpoTenantRecycleBinItemRestoreCommand_initValidators, _SpoTenantRecycleBinItemRestoreCommand_initTypes;
|
|
7
7
|
import request from '../../../../request.js';
|
|
8
8
|
import { formatting } from '../../../../utils/formatting.js';
|
|
9
9
|
import { odata } from '../../../../utils/odata.js';
|
|
@@ -22,11 +22,15 @@ class SpoTenantRecycleBinItemRestoreCommand extends SpoCommand {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
super();
|
|
24
24
|
_SpoTenantRecycleBinItemRestoreCommand_instances.add(this);
|
|
25
|
+
__classPrivateFieldGet(this, _SpoTenantRecycleBinItemRestoreCommand_instances, "m", _SpoTenantRecycleBinItemRestoreCommand_initTelemetry).call(this);
|
|
25
26
|
__classPrivateFieldGet(this, _SpoTenantRecycleBinItemRestoreCommand_instances, "m", _SpoTenantRecycleBinItemRestoreCommand_initOptions).call(this);
|
|
26
27
|
__classPrivateFieldGet(this, _SpoTenantRecycleBinItemRestoreCommand_instances, "m", _SpoTenantRecycleBinItemRestoreCommand_initValidators).call(this);
|
|
27
28
|
__classPrivateFieldGet(this, _SpoTenantRecycleBinItemRestoreCommand_instances, "m", _SpoTenantRecycleBinItemRestoreCommand_initTypes).call(this);
|
|
28
29
|
}
|
|
29
30
|
async commandAction(logger, args) {
|
|
31
|
+
if (args.options.wait) {
|
|
32
|
+
await this.warn(logger, `Option 'wait' is deprecated and will be removed in the next major release.`);
|
|
33
|
+
}
|
|
30
34
|
try {
|
|
31
35
|
if (this.verbose) {
|
|
32
36
|
await logger.logToStderr(`Restoring site collection '${args.options.siteUrl}' from recycle bin.`);
|
|
@@ -58,6 +62,13 @@ class SpoTenantRecycleBinItemRestoreCommand extends SpoCommand {
|
|
|
58
62
|
};
|
|
59
63
|
await request.post(restoreOptions);
|
|
60
64
|
}
|
|
65
|
+
// Here, we return a fixed response because this new API endpoint doesn't return a response while the previous API did.
|
|
66
|
+
// This has to be removed in the next major release.
|
|
67
|
+
await logger.log({
|
|
68
|
+
HasTimedout: false,
|
|
69
|
+
IsComplete: !!args.options.wait,
|
|
70
|
+
PollingInterval: 15000
|
|
71
|
+
});
|
|
61
72
|
}
|
|
62
73
|
catch (err) {
|
|
63
74
|
this.handleRejectedODataJsonPromise(err);
|
|
@@ -68,14 +79,23 @@ class SpoTenantRecycleBinItemRestoreCommand extends SpoCommand {
|
|
|
68
79
|
return sites[0].GroupId;
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
|
-
_SpoTenantRecycleBinItemRestoreCommand_instances = new WeakSet(),
|
|
82
|
+
_SpoTenantRecycleBinItemRestoreCommand_instances = new WeakSet(), _SpoTenantRecycleBinItemRestoreCommand_initTelemetry = function _SpoTenantRecycleBinItemRestoreCommand_initTelemetry() {
|
|
83
|
+
this.telemetry.push((args) => {
|
|
84
|
+
Object.assign(this.telemetryProperties, {
|
|
85
|
+
wait: !!args.options.wait
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}, _SpoTenantRecycleBinItemRestoreCommand_initOptions = function _SpoTenantRecycleBinItemRestoreCommand_initOptions() {
|
|
72
89
|
this.options.unshift({
|
|
73
90
|
option: '-u, --siteUrl <siteUrl>'
|
|
91
|
+
}, {
|
|
92
|
+
option: '--wait'
|
|
74
93
|
});
|
|
75
94
|
}, _SpoTenantRecycleBinItemRestoreCommand_initValidators = function _SpoTenantRecycleBinItemRestoreCommand_initValidators() {
|
|
76
95
|
this.validators.push(async (args) => validation.isValidSharePointUrl(args.options.siteUrl));
|
|
77
96
|
}, _SpoTenantRecycleBinItemRestoreCommand_initTypes = function _SpoTenantRecycleBinItemRestoreCommand_initTypes() {
|
|
78
97
|
this.types.string.push('siteUrl');
|
|
98
|
+
this.types.boolean.push('wait');
|
|
79
99
|
};
|
|
80
100
|
export default new SpoTenantRecycleBinItemRestoreCommand();
|
|
81
101
|
//# sourceMappingURL=tenant-recyclebinitem-restore.js.map
|
|
@@ -92,6 +92,7 @@ export default {
|
|
|
92
92
|
FOLDER_LIST: `${prefix} folder list`,
|
|
93
93
|
FOLDER_MOVE: `${prefix} folder move`,
|
|
94
94
|
FOLDER_REMOVE: `${prefix} folder remove`,
|
|
95
|
+
FOLDER_RENAME: `${prefix} folder rename`,
|
|
95
96
|
FOLDER_SET: `${prefix} folder set`,
|
|
96
97
|
FOLDER_RETENTIONLABEL_ENSURE: `${prefix} folder retentionlabel ensure`,
|
|
97
98
|
FOLDER_RETENTIONLABEL_REMOVE: `${prefix} folder retentionlabel remove`,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _TeamsMessageRestoreCommand_instances, _TeamsMessageRestoreCommand_initTelemetry, _TeamsMessageRestoreCommand_initOptions, _TeamsMessageRestoreCommand_initValidators, _TeamsMessageRestoreCommand_initOptionSets, _TeamsMessageRestoreCommand_initTypes;
|
|
7
|
+
import request from '../../../../request.js';
|
|
8
|
+
import { validation } from '../../../../utils/validation.js';
|
|
9
|
+
import commands from '../../commands.js';
|
|
10
|
+
import DelegatedGraphCommand from '../../../base/DelegatedGraphCommand.js';
|
|
11
|
+
import { teams } from '../../../../utils/teams.js';
|
|
12
|
+
class TeamsMessageRestoreCommand extends DelegatedGraphCommand {
|
|
13
|
+
get name() {
|
|
14
|
+
return commands.MESSAGE_RESTORE;
|
|
15
|
+
}
|
|
16
|
+
get description() {
|
|
17
|
+
return 'Restores a deleted message from a channel in a Microsoft Teams team';
|
|
18
|
+
}
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
_TeamsMessageRestoreCommand_instances.add(this);
|
|
22
|
+
__classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initTelemetry).call(this);
|
|
23
|
+
__classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initOptions).call(this);
|
|
24
|
+
__classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initValidators).call(this);
|
|
25
|
+
__classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initOptionSets).call(this);
|
|
26
|
+
__classPrivateFieldGet(this, _TeamsMessageRestoreCommand_instances, "m", _TeamsMessageRestoreCommand_initTypes).call(this);
|
|
27
|
+
}
|
|
28
|
+
async commandAction(logger, args) {
|
|
29
|
+
try {
|
|
30
|
+
if (this.verbose) {
|
|
31
|
+
await logger.logToStderr(`Restoring deleted message '${args.options.id}' from channel '${args.options.channelId || args.options.channelName}' in the Microsoft Teams team '${args.options.teamId || args.options.teamName}'.`);
|
|
32
|
+
}
|
|
33
|
+
const teamId = await this.getTeamId(args.options, logger);
|
|
34
|
+
const channelId = await this.getChannelId(args.options, teamId, logger);
|
|
35
|
+
const requestOptions = {
|
|
36
|
+
url: `${this.resource}/v1.0/teams/${teamId}/channels/${channelId}/messages/${args.options.id}/undoSoftDelete`,
|
|
37
|
+
headers: {
|
|
38
|
+
accept: 'application/json;odata.metadata=none'
|
|
39
|
+
},
|
|
40
|
+
responseType: 'json'
|
|
41
|
+
};
|
|
42
|
+
await request.post(requestOptions);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.handleRejectedODataJsonPromise(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async getTeamId(options, logger) {
|
|
49
|
+
if (options.teamId) {
|
|
50
|
+
return options.teamId;
|
|
51
|
+
}
|
|
52
|
+
if (this.verbose) {
|
|
53
|
+
await logger.logToStderr(`Getting the Team ID.`);
|
|
54
|
+
}
|
|
55
|
+
const groupId = await teams.getTeamIdByDisplayName(options.teamName);
|
|
56
|
+
return groupId;
|
|
57
|
+
}
|
|
58
|
+
async getChannelId(options, teamId, logger) {
|
|
59
|
+
if (options.channelId) {
|
|
60
|
+
return options.channelId;
|
|
61
|
+
}
|
|
62
|
+
if (this.verbose) {
|
|
63
|
+
await logger.logToStderr(`Getting the channel ID.`);
|
|
64
|
+
}
|
|
65
|
+
const channelId = await teams.getChannelIdByDisplayName(teamId, options.channelName);
|
|
66
|
+
return channelId;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_TeamsMessageRestoreCommand_instances = new WeakSet(), _TeamsMessageRestoreCommand_initTelemetry = function _TeamsMessageRestoreCommand_initTelemetry() {
|
|
70
|
+
this.telemetry.push((args) => {
|
|
71
|
+
Object.assign(this.telemetryProperties, {
|
|
72
|
+
teamId: typeof args.options.teamId !== 'undefined',
|
|
73
|
+
teamName: typeof args.options.teamName !== 'undefined',
|
|
74
|
+
channelId: typeof args.options.channelId !== 'undefined',
|
|
75
|
+
channelName: typeof args.options.channelName !== 'undefined'
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}, _TeamsMessageRestoreCommand_initOptions = function _TeamsMessageRestoreCommand_initOptions() {
|
|
79
|
+
this.options.unshift({
|
|
80
|
+
option: '--teamId [teamId]'
|
|
81
|
+
}, {
|
|
82
|
+
option: '--teamName [teamName]'
|
|
83
|
+
}, {
|
|
84
|
+
option: '--channelId [channelId]'
|
|
85
|
+
}, {
|
|
86
|
+
option: '--channelName [channelName]'
|
|
87
|
+
}, {
|
|
88
|
+
option: '-i, --id <id>'
|
|
89
|
+
});
|
|
90
|
+
}, _TeamsMessageRestoreCommand_initValidators = function _TeamsMessageRestoreCommand_initValidators() {
|
|
91
|
+
this.validators.push(async (args) => {
|
|
92
|
+
if (args.options.teamId && !validation.isValidGuid(args.options.teamId)) {
|
|
93
|
+
return `'${args.options.teamId}' is not a valid GUID for 'teamId'.`;
|
|
94
|
+
}
|
|
95
|
+
if (args.options.channelId && !validation.isValidTeamsChannelId(args.options.channelId)) {
|
|
96
|
+
return `'${args.options.channelId}' is not a valid ID for 'channelId'.`;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
}, _TeamsMessageRestoreCommand_initOptionSets = function _TeamsMessageRestoreCommand_initOptionSets() {
|
|
101
|
+
this.optionSets.push({ options: ['teamId', 'teamName'] }, { options: ['channelId', 'channelName'] });
|
|
102
|
+
}, _TeamsMessageRestoreCommand_initTypes = function _TeamsMessageRestoreCommand_initTypes() {
|
|
103
|
+
this.types.string.push('teamId', 'teamName', 'channelId', 'channelName', 'id');
|
|
104
|
+
};
|
|
105
|
+
export default new TeamsMessageRestoreCommand();
|
|
106
|
+
//# sourceMappingURL=message-restore.js.map
|
|
@@ -39,6 +39,7 @@ export default {
|
|
|
39
39
|
MESSAGE_LIST: `${prefix} message list`,
|
|
40
40
|
MESSAGE_REMOVE: `${prefix} message remove`,
|
|
41
41
|
MESSAGE_REPLY_LIST: `${prefix} message reply list`,
|
|
42
|
+
MESSAGE_RESTORE: `${prefix} message restore`,
|
|
42
43
|
MESSAGE_SEND: `${prefix} message send`,
|
|
43
44
|
MESSAGINGSETTINGS_LIST: `${prefix} messagingsettings list`,
|
|
44
45
|
MESSAGINGSETTINGS_SET: `${prefix} messagingsettings set`,
|
package/dist/settingsNames.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const settingsNames = {
|
|
2
2
|
authType: 'authType',
|
|
3
3
|
autoOpenLinksInBrowser: 'autoOpenLinksInBrowser',
|
|
4
|
+
clientId: 'clientId',
|
|
5
|
+
clientSecret: 'clientSecret',
|
|
6
|
+
clientCertificateFile: 'clientCertificateFile',
|
|
7
|
+
clientCertificateBase64Encoded: 'clientCertificateBase64Encoded',
|
|
8
|
+
clientCertificatePassword: 'clientCertificatePassword',
|
|
4
9
|
copyDeviceCodeToClipboard: 'copyDeviceCodeToClipboard',
|
|
5
10
|
csvEscape: 'csvEscape',
|
|
6
11
|
csvHeader: 'csvHeader',
|
|
@@ -16,7 +21,8 @@ const settingsNames = {
|
|
|
16
21
|
prompt: 'prompt',
|
|
17
22
|
promptListPageSize: 'promptListPageSize',
|
|
18
23
|
showHelpOnFailure: 'showHelpOnFailure',
|
|
19
|
-
showSpinner: 'showSpinner'
|
|
24
|
+
showSpinner: 'showSpinner',
|
|
25
|
+
tenantId: 'tenantId'
|
|
20
26
|
};
|
|
21
27
|
export { settingsNames };
|
|
22
28
|
//# sourceMappingURL=settingsNames.js.map
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import request from '../request.js';
|
|
3
|
+
import { odata } from './odata.js';
|
|
4
|
+
async function getCertificateBase64Encoded({ options, logger, debug }) {
|
|
5
|
+
if (options.certificateBase64Encoded) {
|
|
6
|
+
return options.certificateBase64Encoded;
|
|
7
|
+
}
|
|
8
|
+
if (debug) {
|
|
9
|
+
await logger.logToStderr(`Reading existing ${options.certificateFile}...`);
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
return fs.readFileSync(options.certificateFile, { encoding: 'base64' });
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
throw new Error(`Error reading certificate file: ${e}. Please add the certificate using base64 option '--certificateBase64Encoded'.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function createServicePrincipal(appId) {
|
|
19
|
+
const requestOptions = {
|
|
20
|
+
url: `https://graph.microsoft.com/v1.0/myorganization/servicePrincipals`,
|
|
21
|
+
headers: {
|
|
22
|
+
'content-type': 'application/json'
|
|
23
|
+
},
|
|
24
|
+
data: {
|
|
25
|
+
appId: appId
|
|
26
|
+
},
|
|
27
|
+
responseType: 'json'
|
|
28
|
+
};
|
|
29
|
+
return request.post(requestOptions);
|
|
30
|
+
}
|
|
31
|
+
async function grantOAuth2Permission({ appId, resourceId, scopeName }) {
|
|
32
|
+
const grantAdminConsentApplicationRequestOptions = {
|
|
33
|
+
url: `https://graph.microsoft.com/v1.0/myorganization/oauth2PermissionGrants`,
|
|
34
|
+
headers: {
|
|
35
|
+
accept: 'application/json;odata.metadata=none'
|
|
36
|
+
},
|
|
37
|
+
responseType: 'json',
|
|
38
|
+
data: {
|
|
39
|
+
clientId: appId,
|
|
40
|
+
consentType: "AllPrincipals",
|
|
41
|
+
principalId: null,
|
|
42
|
+
resourceId: resourceId,
|
|
43
|
+
scope: scopeName
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return request.post(grantAdminConsentApplicationRequestOptions);
|
|
47
|
+
}
|
|
48
|
+
async function addRoleToServicePrincipal({ objectId, resourceId, appRoleId }) {
|
|
49
|
+
const requestOptions = {
|
|
50
|
+
url: `https://graph.microsoft.com/v1.0/myorganization/servicePrincipals/${objectId}/appRoleAssignments`,
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json'
|
|
53
|
+
},
|
|
54
|
+
responseType: 'json',
|
|
55
|
+
data: {
|
|
56
|
+
appRoleId: appRoleId,
|
|
57
|
+
principalId: objectId,
|
|
58
|
+
resourceId: resourceId
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return request.post(requestOptions);
|
|
62
|
+
}
|
|
63
|
+
async function getRequiredResourceAccessForApis({ servicePrincipals, apis, scopeType, logger, debug }) {
|
|
64
|
+
if (!apis) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const resolvedApis = [];
|
|
68
|
+
const requestedApis = apis.split(',').map(a => a.trim());
|
|
69
|
+
for (const api of requestedApis) {
|
|
70
|
+
const pos = api.lastIndexOf('/');
|
|
71
|
+
const permissionName = api.substring(pos + 1);
|
|
72
|
+
const servicePrincipalName = api.substring(0, pos);
|
|
73
|
+
if (debug) {
|
|
74
|
+
await logger.logToStderr(`Resolving ${api}...`);
|
|
75
|
+
await logger.logToStderr(`Permission name: ${permissionName}`);
|
|
76
|
+
await logger.logToStderr(`Service principal name: ${servicePrincipalName}`);
|
|
77
|
+
}
|
|
78
|
+
const servicePrincipal = servicePrincipals.find(sp => (sp.servicePrincipalNames.indexOf(servicePrincipalName) > -1 ||
|
|
79
|
+
sp.servicePrincipalNames.indexOf(`${servicePrincipalName}/`) > -1));
|
|
80
|
+
if (!servicePrincipal) {
|
|
81
|
+
throw `Service principal ${servicePrincipalName} not found`;
|
|
82
|
+
}
|
|
83
|
+
const scopesOfType = scopeType === 'Scope' ? servicePrincipal.oauth2PermissionScopes : servicePrincipal.appRoles;
|
|
84
|
+
const permission = scopesOfType.find(scope => scope.value === permissionName);
|
|
85
|
+
if (!permission) {
|
|
86
|
+
throw `Permission ${permissionName} for service principal ${servicePrincipalName} not found`;
|
|
87
|
+
}
|
|
88
|
+
let resolvedApi = resolvedApis.find(a => a.resourceAppId === servicePrincipal.appId);
|
|
89
|
+
if (!resolvedApi) {
|
|
90
|
+
resolvedApi = {
|
|
91
|
+
resourceAppId: servicePrincipal.appId,
|
|
92
|
+
resourceAccess: []
|
|
93
|
+
};
|
|
94
|
+
resolvedApis.push(resolvedApi);
|
|
95
|
+
}
|
|
96
|
+
const resourceAccessPermission = {
|
|
97
|
+
id: permission.id,
|
|
98
|
+
type: scopeType
|
|
99
|
+
};
|
|
100
|
+
resolvedApi.resourceAccess.push(resourceAccessPermission);
|
|
101
|
+
updateAppPermissions({
|
|
102
|
+
spId: servicePrincipal.id,
|
|
103
|
+
resourceAccessPermission,
|
|
104
|
+
oAuth2PermissionValue: permission.value
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return resolvedApis;
|
|
108
|
+
}
|
|
109
|
+
function updateAppPermissions({ spId, resourceAccessPermission, oAuth2PermissionValue }) {
|
|
110
|
+
// During API resolution, we store globally both app role assignments and oauth2permissions
|
|
111
|
+
// So that we'll be able to parse them during the admin consent process
|
|
112
|
+
let existingPermission = entraApp.appPermissions.find(oauth => oauth.resourceId === spId);
|
|
113
|
+
if (!existingPermission) {
|
|
114
|
+
existingPermission = {
|
|
115
|
+
resourceId: spId,
|
|
116
|
+
resourceAccess: [],
|
|
117
|
+
scope: []
|
|
118
|
+
};
|
|
119
|
+
entraApp.appPermissions.push(existingPermission);
|
|
120
|
+
}
|
|
121
|
+
if (resourceAccessPermission.type === 'Scope' && oAuth2PermissionValue && !existingPermission.scope.find(scp => scp === oAuth2PermissionValue)) {
|
|
122
|
+
existingPermission.scope.push(oAuth2PermissionValue);
|
|
123
|
+
}
|
|
124
|
+
if (!existingPermission.resourceAccess.find(res => res.id === resourceAccessPermission.id)) {
|
|
125
|
+
existingPermission.resourceAccess.push(resourceAccessPermission);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export const entraApp = {
|
|
129
|
+
appPermissions: [],
|
|
130
|
+
createAppRegistration: async ({ options, apis, logger, verbose, debug }) => {
|
|
131
|
+
const applicationInfo = {
|
|
132
|
+
displayName: options.name,
|
|
133
|
+
signInAudience: options.multitenant ? 'AzureADMultipleOrgs' : 'AzureADMyOrg'
|
|
134
|
+
};
|
|
135
|
+
if (apis.length > 0) {
|
|
136
|
+
applicationInfo.requiredResourceAccess = apis;
|
|
137
|
+
}
|
|
138
|
+
if (options.redirectUris) {
|
|
139
|
+
applicationInfo[options.platform] = {
|
|
140
|
+
redirectUris: options.redirectUris.split(',').map(u => u.trim())
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (options.implicitFlow) {
|
|
144
|
+
if (!applicationInfo.web) {
|
|
145
|
+
applicationInfo.web = {};
|
|
146
|
+
}
|
|
147
|
+
applicationInfo.web.implicitGrantSettings = {
|
|
148
|
+
enableAccessTokenIssuance: true,
|
|
149
|
+
enableIdTokenIssuance: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (options.certificateFile || options.certificateBase64Encoded) {
|
|
153
|
+
const certificateBase64Encoded = await getCertificateBase64Encoded({ options, logger, debug });
|
|
154
|
+
const newKeyCredential = {
|
|
155
|
+
type: 'AsymmetricX509Cert',
|
|
156
|
+
usage: 'Verify',
|
|
157
|
+
displayName: options.certificateDisplayName,
|
|
158
|
+
key: certificateBase64Encoded
|
|
159
|
+
};
|
|
160
|
+
applicationInfo.keyCredentials = [newKeyCredential];
|
|
161
|
+
}
|
|
162
|
+
if (options.allowPublicClientFlows) {
|
|
163
|
+
applicationInfo.isFallbackPublicClient = true;
|
|
164
|
+
}
|
|
165
|
+
if (verbose) {
|
|
166
|
+
await logger.logToStderr(`Creating Microsoft Entra app registration...`);
|
|
167
|
+
}
|
|
168
|
+
const createApplicationRequestOptions = {
|
|
169
|
+
url: `https://graph.microsoft.com/v1.0/myorganization/applications`,
|
|
170
|
+
headers: {
|
|
171
|
+
accept: 'application/json;odata.metadata=none'
|
|
172
|
+
},
|
|
173
|
+
responseType: 'json',
|
|
174
|
+
data: applicationInfo
|
|
175
|
+
};
|
|
176
|
+
return request.post(createApplicationRequestOptions);
|
|
177
|
+
},
|
|
178
|
+
grantAdminConsent: async ({ appInfo, appPermissions, adminConsent, logger, debug }) => {
|
|
179
|
+
if (!adminConsent || appPermissions.length === 0) {
|
|
180
|
+
return appInfo;
|
|
181
|
+
}
|
|
182
|
+
const sp = await createServicePrincipal(appInfo.appId);
|
|
183
|
+
if (debug) {
|
|
184
|
+
await logger.logToStderr("Service principal created, returned object id: " + sp.id);
|
|
185
|
+
}
|
|
186
|
+
const tasks = [];
|
|
187
|
+
appPermissions.forEach(async (permission) => {
|
|
188
|
+
if (permission.scope.length > 0) {
|
|
189
|
+
tasks.push(grantOAuth2Permission({
|
|
190
|
+
appId: sp.id,
|
|
191
|
+
resourceId: permission.resourceId,
|
|
192
|
+
scopeName: permission.scope.join(' ')
|
|
193
|
+
}));
|
|
194
|
+
if (debug) {
|
|
195
|
+
await logger.logToStderr(`Admin consent granted for following resource ${permission.resourceId}, with delegated permissions: ${permission.scope.join(',')}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
permission.resourceAccess.filter(access => access.type === "Role").forEach(async (access) => {
|
|
199
|
+
tasks.push(addRoleToServicePrincipal({
|
|
200
|
+
objectId: sp.id,
|
|
201
|
+
resourceId: permission.resourceId,
|
|
202
|
+
appRoleId: access.id
|
|
203
|
+
}));
|
|
204
|
+
if (debug) {
|
|
205
|
+
await logger.logToStderr(`Admin consent granted for following resource ${permission.resourceId}, with application permission: ${access.id}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
await Promise.all(tasks);
|
|
210
|
+
return appInfo;
|
|
211
|
+
},
|
|
212
|
+
resolveApis: async ({ options, manifest, logger, verbose, debug }) => {
|
|
213
|
+
if (!options.apisDelegated && !options.apisApplication
|
|
214
|
+
&& (typeof manifest?.requiredResourceAccess === 'undefined' || manifest.requiredResourceAccess.length === 0)) {
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
if (verbose) {
|
|
218
|
+
await logger.logToStderr('Resolving requested APIs...');
|
|
219
|
+
}
|
|
220
|
+
const servicePrincipals = await odata.getAllItems(`https://graph.microsoft.com/v1.0/myorganization/servicePrincipals?$select=appId,appRoles,id,oauth2PermissionScopes,servicePrincipalNames`);
|
|
221
|
+
let resolvedApis = [];
|
|
222
|
+
if (options.apisDelegated || options.apisApplication) {
|
|
223
|
+
resolvedApis = await getRequiredResourceAccessForApis({
|
|
224
|
+
servicePrincipals,
|
|
225
|
+
apis: options.apisDelegated,
|
|
226
|
+
scopeType: 'Scope',
|
|
227
|
+
logger,
|
|
228
|
+
debug
|
|
229
|
+
});
|
|
230
|
+
if (verbose) {
|
|
231
|
+
await logger.logToStderr(`Resolved delegated permissions: ${JSON.stringify(resolvedApis, null, 2)}`);
|
|
232
|
+
}
|
|
233
|
+
const resolvedApplicationApis = await getRequiredResourceAccessForApis({
|
|
234
|
+
servicePrincipals,
|
|
235
|
+
apis: options.apisApplication,
|
|
236
|
+
scopeType: 'Role',
|
|
237
|
+
logger,
|
|
238
|
+
debug
|
|
239
|
+
});
|
|
240
|
+
if (verbose) {
|
|
241
|
+
await logger.logToStderr(`Resolved application permissions: ${JSON.stringify(resolvedApplicationApis, null, 2)}`);
|
|
242
|
+
}
|
|
243
|
+
// merge resolved application APIs onto resolved delegated APIs
|
|
244
|
+
resolvedApplicationApis.forEach(resolvedRequiredResource => {
|
|
245
|
+
const requiredResource = resolvedApis.find(api => api.resourceAppId === resolvedRequiredResource.resourceAppId);
|
|
246
|
+
if (requiredResource) {
|
|
247
|
+
requiredResource.resourceAccess.push(...resolvedRequiredResource.resourceAccess);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
resolvedApis.push(resolvedRequiredResource);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const manifestApis = manifest.requiredResourceAccess;
|
|
256
|
+
manifestApis.forEach(manifestApi => {
|
|
257
|
+
resolvedApis.push(manifestApi);
|
|
258
|
+
const app = servicePrincipals.find(servicePrincipals => servicePrincipals.appId === manifestApi.resourceAppId);
|
|
259
|
+
if (app) {
|
|
260
|
+
manifestApi.resourceAccess.forEach((res => {
|
|
261
|
+
const resourceAccessPermission = {
|
|
262
|
+
id: res.id,
|
|
263
|
+
type: res.type
|
|
264
|
+
};
|
|
265
|
+
const oAuthValue = app.oauth2PermissionScopes.find(scp => scp.id === res.id)?.value;
|
|
266
|
+
updateAppPermissions({
|
|
267
|
+
spId: app.id,
|
|
268
|
+
resourceAccessPermission,
|
|
269
|
+
oAuth2PermissionValue: oAuthValue
|
|
270
|
+
});
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (verbose) {
|
|
276
|
+
await logger.logToStderr(`Merged delegated and application permissions: ${JSON.stringify(resolvedApis, null, 2)}`);
|
|
277
|
+
await logger.logToStderr(`App role assignments: ${JSON.stringify(entraApp.appPermissions.flatMap(permission => permission.resourceAccess.filter(access => access.type === "Role")), null, 2)}`);
|
|
278
|
+
await logger.logToStderr(`OAuth2 permissions: ${JSON.stringify(entraApp.appPermissions.flatMap(permission => permission.scope), null, 2)}`);
|
|
279
|
+
}
|
|
280
|
+
return resolvedApis;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=entraApp.js.map
|
package/dist/utils/spo.js
CHANGED
|
@@ -12,16 +12,6 @@ import { RoleType } from '../m365/spo/commands/roledefinition/RoleType.js';
|
|
|
12
12
|
import { entraGroup } from './entraGroup.js';
|
|
13
13
|
import { SharingCapabilities } from '../m365/spo/commands/site/SharingCapabilities.js';
|
|
14
14
|
import { setTimeout } from 'timers/promises';
|
|
15
|
-
export var CreateCopyJobsNameConflictBehavior;
|
|
16
|
-
(function (CreateCopyJobsNameConflictBehavior) {
|
|
17
|
-
CreateCopyJobsNameConflictBehavior[CreateCopyJobsNameConflictBehavior["Fail"] = 0] = "Fail";
|
|
18
|
-
CreateCopyJobsNameConflictBehavior[CreateCopyJobsNameConflictBehavior["Replace"] = 1] = "Replace";
|
|
19
|
-
CreateCopyJobsNameConflictBehavior[CreateCopyJobsNameConflictBehavior["Rename"] = 2] = "Rename";
|
|
20
|
-
})(CreateCopyJobsNameConflictBehavior || (CreateCopyJobsNameConflictBehavior = {}));
|
|
21
|
-
// Wrapping this into a settings object so we can alter the values in tests
|
|
22
|
-
export const settings = {
|
|
23
|
-
pollingInterval: 3000
|
|
24
|
-
};
|
|
25
15
|
export const spo = {
|
|
26
16
|
async getRequestDigest(siteUrl) {
|
|
27
17
|
const requestOptions = {
|
|
@@ -1526,70 +1516,6 @@ export const spo = {
|
|
|
1526
1516
|
};
|
|
1527
1517
|
const itemsResponse = await request.get(requestOptionsItems);
|
|
1528
1518
|
return (itemsResponse);
|
|
1529
|
-
},
|
|
1530
|
-
/**
|
|
1531
|
-
* Create a SharePoint copy job to copy a file/folder to another location.
|
|
1532
|
-
* @param webUrl Absolute web URL where the source file/folder is located.
|
|
1533
|
-
* @param sourceUrl Absolute URL of the source file/folder.
|
|
1534
|
-
* @param destinationUrl Absolute URL of the destination folder.
|
|
1535
|
-
* @param options Options for the copy job.
|
|
1536
|
-
* @returns Copy job information. Use {@link spo.getCopyJobResult} to get the result of the copy job.
|
|
1537
|
-
*/
|
|
1538
|
-
async createCopyJob(webUrl, sourceUrl, destinationUrl, options) {
|
|
1539
|
-
const requestOptions = {
|
|
1540
|
-
url: `${webUrl}/_api/Site/CreateCopyJobs`,
|
|
1541
|
-
headers: {
|
|
1542
|
-
accept: 'application/json;odata=nometadata'
|
|
1543
|
-
},
|
|
1544
|
-
responseType: 'json',
|
|
1545
|
-
data: {
|
|
1546
|
-
destinationUri: destinationUrl,
|
|
1547
|
-
exportObjectUris: [sourceUrl],
|
|
1548
|
-
options: {
|
|
1549
|
-
NameConflictBehavior: options?.nameConflictBehavior ?? CreateCopyJobsNameConflictBehavior.Fail,
|
|
1550
|
-
AllowSchemaMismatch: true,
|
|
1551
|
-
BypassSharedLock: !!options?.bypassSharedLock,
|
|
1552
|
-
IgnoreVersionHistory: !!options?.ignoreVersionHistory,
|
|
1553
|
-
CustomizedItemName: options?.newName ? [options.newName] : undefined,
|
|
1554
|
-
SameWebCopyMoveOptimization: true
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
const response = await request.post(requestOptions);
|
|
1559
|
-
return response.value[0];
|
|
1560
|
-
},
|
|
1561
|
-
/**
|
|
1562
|
-
* Poll until the copy job is finished and return the result.
|
|
1563
|
-
* @param webUrl Absolute web URL where the copy job was created.
|
|
1564
|
-
* @param copyJobInfo Information about the copy job.
|
|
1565
|
-
* @throws Error if the copy job has failed.
|
|
1566
|
-
* @returns Information about the destination object.
|
|
1567
|
-
*/
|
|
1568
|
-
async getCopyJobResult(webUrl, copyJobInfo) {
|
|
1569
|
-
const requestOptions = {
|
|
1570
|
-
url: `${webUrl}/_api/Site/GetCopyJobProgress`,
|
|
1571
|
-
headers: {
|
|
1572
|
-
accept: 'application/json;odata=nometadata'
|
|
1573
|
-
},
|
|
1574
|
-
responseType: 'json',
|
|
1575
|
-
data: {
|
|
1576
|
-
copyJobInfo: copyJobInfo
|
|
1577
|
-
}
|
|
1578
|
-
};
|
|
1579
|
-
let progress = await request.post(requestOptions);
|
|
1580
|
-
while (progress.JobState !== 0) {
|
|
1581
|
-
await setTimeout(settings.pollingInterval);
|
|
1582
|
-
progress = await request.post(requestOptions);
|
|
1583
|
-
}
|
|
1584
|
-
const logs = progress.Logs.map(l => JSON.parse(l));
|
|
1585
|
-
// Check if the job has failed
|
|
1586
|
-
const errorLog = logs.find(l => l.Event === 'JobError');
|
|
1587
|
-
if (errorLog) {
|
|
1588
|
-
throw new Error(errorLog.Message);
|
|
1589
|
-
}
|
|
1590
|
-
// Get the destination object information
|
|
1591
|
-
const objectInfo = logs.find(l => l.Event === 'JobFinishedObjectInfo');
|
|
1592
|
-
return objectInfo;
|
|
1593
1519
|
}
|
|
1594
1520
|
};
|
|
1595
1521
|
//# sourceMappingURL=spo.js.map
|
|
@@ -2,6 +2,11 @@ Setting name|Definition|Default value
|
|
|
2
2
|
------------|----------|-------------
|
|
3
3
|
`authType`|Default login method to use when running `m365 login` without the `--authType` option.|`deviceCode`
|
|
4
4
|
`autoOpenLinksInBrowser`|Automatically open the browser for all commands which return a url and expect the user to copy paste this to the browser. For example when logging in, using `m365 login` in device code mode.|`false`
|
|
5
|
+
`clientId`|ID of the default Entra ID app use by the CLI to authenticate|``
|
|
6
|
+
`clientSecret`|Secret of the default Entra ID app use by the CLI to authenticate|``
|
|
7
|
+
`clientCertificateFile`|Path to the file containing the client certificate to use for authentication|``
|
|
8
|
+
`clientCertificateBase64Encoded`|Base64-encoded client certificate contents|``
|
|
9
|
+
`clientCertificatePassword`|Password to the client certificate file|``
|
|
5
10
|
`copyDeviceCodeToClipboard`|Automatically copy the device code to the clipboard when running `m365 login` command in device code mode|`false`
|
|
6
11
|
`csvEscape`|Single character used for escaping; only apply to characters matching the quote and the escape options|`"`
|
|
7
12
|
`csvHeader`|Display the column names on the first line|`true`
|
|
@@ -18,3 +23,4 @@ Setting name|Definition|Default value
|
|
|
18
23
|
`promptListPageSize`|By default, lists of choices longer than 7 will be paginated. Use this option to control how many choices will appear on the screen at once.|7
|
|
19
24
|
`showHelpOnFailure`|Automatically display help when executing a command failed|`true`
|
|
20
25
|
`showSpinner`|Display spinner when executing commands|`true`
|
|
26
|
+
`tenantId`|ID of the default tenant to use when authenticating with|``
|
|
@@ -16,10 +16,10 @@ m365 app permission add [options]
|
|
|
16
16
|
`--appId [appId]`
|
|
17
17
|
: Client ID of the Microsoft Entra app registered in the .m365rc.json file to retrieve API permissions for.
|
|
18
18
|
|
|
19
|
-
`--
|
|
19
|
+
`--applicationPermission [applicationPermission]`
|
|
20
20
|
: Space-separated list of application permissions to add.
|
|
21
21
|
|
|
22
|
-
`--
|
|
22
|
+
`--delegatedPermission [delegatedPermission]`
|
|
23
23
|
: Space-separated list of delegated permissions to add.
|
|
24
24
|
|
|
25
25
|
`--grantAdminConsent`
|
|
@@ -37,19 +37,19 @@ If you have multiple apps registered in your .m365rc.json file, you can specify
|
|
|
37
37
|
Adds the specified application permissions to the default app registered in the _.m365rc.json_ file while granting admin consent.
|
|
38
38
|
|
|
39
39
|
```sh
|
|
40
|
-
m365 app permission add --
|
|
40
|
+
m365 app permission add --applicationPermission 'https://graph.microsoft.com/User.ReadWrite.All https://graph.microsoft.com/User.Read.All' --grantAdminConsent
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Adds the specified delegated permissions to the default app registered in the _.m365rc.json_ file without granting admin consent.
|
|
44
44
|
|
|
45
45
|
```sh
|
|
46
|
-
m365 app permission add --
|
|
46
|
+
m365 app permission add --delegatedPermission 'https://graph.microsoft.com/offline_access'
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
Adds the specified application and delegated permissions to a specific app registered in the _.m365rc.json_ file while granting admin consent.
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
|
-
m365 app permission add --appId '1663767b-4172-4519-bfd1-28e6ff19055b' --
|
|
52
|
+
m365 app permission add --appId '1663767b-4172-4519-bfd1-28e6ff19055b' --applicationPermission 'https://graph.microsoft.com/User.ReadWrite.All https://graph.microsoft.com/User.Read.All' --delegatedPermission 'https://graph.microsoft.com/offline_access' --grantAdminConsent
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
## Response
|