@pnp/cli-microsoft365 10.0.0-beta.48e9f7d → 10.0.0-beta.787c5f1
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 +4 -1
- package/dist/cli/cli.js +14 -0
- package/dist/config.js +60 -5
- package/dist/m365/base/PowerAutomateCommand.js +1 -1
- 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 -4
- package/dist/m365/commands/login.js +28 -9
- package/dist/m365/commands/setup.js +256 -33
- package/dist/m365/commands/setupPresets.js +2 -4
- package/dist/m365/connection/commands/connection-list.js +4 -4
- package/dist/m365/entra/commands/app/app-add.js +52 -288
- package/dist/m365/flow/commands/environment/environment-get.js +1 -1
- package/dist/m365/flow/commands/environment/environment-list.js +1 -1
- package/dist/m365/flow/commands/flow-disable.js +1 -1
- package/dist/m365/flow/commands/flow-enable.js +1 -1
- package/dist/m365/flow/commands/flow-export.js +17 -16
- package/dist/m365/flow/commands/flow-get.js +1 -1
- package/dist/m365/flow/commands/flow-list.js +1 -1
- package/dist/m365/flow/commands/flow-remove.js +1 -1
- package/dist/m365/flow/commands/owner/owner-ensure.js +1 -1
- package/dist/m365/flow/commands/owner/owner-list.js +1 -1
- package/dist/m365/flow/commands/owner/owner-remove.js +1 -1
- package/dist/m365/flow/commands/recyclebinitem/recyclebinitem-list.js +47 -0
- package/dist/m365/flow/commands/recyclebinitem/recyclebinitem-restore.js +48 -0
- package/dist/m365/flow/commands/run/run-cancel.js +1 -1
- package/dist/m365/flow/commands/run/run-get.js +1 -1
- package/dist/m365/flow/commands/run/run-list.js +1 -1
- package/dist/m365/flow/commands/run/run-resubmit.js +2 -2
- package/dist/m365/flow/commands.js +2 -0
- package/dist/m365/spo/commands/contenttype/contenttype-field-remove.js +8 -8
- package/dist/m365/spo/commands/contenttype/contenttype-field-set.js +2 -2
- package/dist/m365/spo/commands/file/file-roleassignment-add.js +17 -54
- package/dist/m365/spo/commands/file/file-roleassignment-remove.js +13 -40
- package/dist/m365/spo/commands/file/file-roleinheritance-break.js +5 -13
- package/dist/m365/spo/commands/file/file-roleinheritance-reset.js +5 -13
- package/dist/m365/spo/commands/folder/folder-sharinglink-add.js +143 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-clear.js +111 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-remove.js +95 -0
- package/dist/m365/spo/commands/list/list-get.js +17 -4
- package/dist/m365/spo/commands/page/page-section-add.js +185 -34
- package/dist/m365/spo/commands/site/SiteAdmin.js +2 -0
- package/dist/m365/spo/commands/site/site-admin-add.js +252 -0
- package/dist/m365/spo/commands/site/site-admin-list.js +2 -27
- package/dist/m365/spo/commands/user/user-get.js +67 -9
- package/dist/m365/spo/commands.js +4 -0
- package/dist/m365/spp/commands/contentcenter/contentcenter-list.js +56 -0
- package/dist/m365/spp/commands.js +5 -0
- package/dist/settingsNames.js +6 -1
- package/dist/utils/entraApp.js +283 -0
- package/dist/utils/spo.js +75 -7
- package/dist/utils/zod.js +1 -1
- package/docs/docs/_clisettings.mdx +6 -1
- package/docs/docs/cmd/flow/recyclebinitem/recyclebinitem-list.mdx +132 -0
- package/docs/docs/cmd/flow/recyclebinitem/recyclebinitem-restore.mdx +55 -0
- package/docs/docs/cmd/setup.mdx +17 -6
- package/docs/docs/cmd/spo/contenttype/contenttype-field-remove.mdx +7 -7
- package/docs/docs/cmd/spo/contenttype/contenttype-field-set.mdx +2 -2
- package/docs/docs/cmd/spo/folder/folder-sharinglink-add.mdx +125 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-clear.mdx +50 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-remove.mdx +50 -0
- package/docs/docs/cmd/spo/page/page-section-add.mdx +57 -2
- package/docs/docs/cmd/spo/site/site-admin-add.mdx +67 -0
- package/docs/docs/cmd/spo/user/user-get.mdx +35 -9
- package/docs/docs/cmd/spp/contentcenter/contentcenter-list.mdx +289 -0
- package/npm-shrinkwrap.json +203 -375
- package/package.json +16 -17
package/dist/Auth.js
CHANGED
|
@@ -4,7 +4,6 @@ import { CommandError } from './Command.js';
|
|
|
4
4
|
import { FileTokenStorage } from './auth/FileTokenStorage.js';
|
|
5
5
|
import { msalCachePlugin } from './auth/msalCachePlugin.js';
|
|
6
6
|
import { cli } from './cli/cli.js';
|
|
7
|
-
import config from './config.js';
|
|
8
7
|
import request from './request.js';
|
|
9
8
|
import { settingsNames } from './settingsNames.js';
|
|
10
9
|
import * as accessTokenUtil from './utils/accessToken.js';
|
|
@@ -22,10 +21,10 @@ export class Connection {
|
|
|
22
21
|
this.active = false;
|
|
23
22
|
this.authType = AuthType.DeviceCode;
|
|
24
23
|
this.certificateType = CertificateType.Unknown;
|
|
24
|
+
// ID of the tenant where the Microsoft Entra app is registered; common if multi-tenant
|
|
25
|
+
this.tenant = 'common';
|
|
25
26
|
this.cloudType = CloudType.Public;
|
|
26
27
|
this.accessTokens = {};
|
|
27
|
-
this.appId = config.cliEntraAppId;
|
|
28
|
-
this.tenant = config.tenant;
|
|
29
28
|
this.cloudType = CloudType.Public;
|
|
30
29
|
}
|
|
31
30
|
deactivate() {
|
|
@@ -44,18 +43,18 @@ export class Connection {
|
|
|
44
43
|
this.thumbprint = undefined;
|
|
45
44
|
this.spoUrl = undefined;
|
|
46
45
|
this.spoTenantId = undefined;
|
|
47
|
-
this.appId =
|
|
48
|
-
this.tenant =
|
|
46
|
+
this.appId = cli.getClientId();
|
|
47
|
+
this.tenant = cli.getTenant();
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
export var AuthType;
|
|
52
51
|
(function (AuthType) {
|
|
53
|
-
AuthType[
|
|
54
|
-
AuthType[
|
|
55
|
-
AuthType[
|
|
56
|
-
AuthType[
|
|
57
|
-
AuthType[
|
|
58
|
-
AuthType[
|
|
52
|
+
AuthType["DeviceCode"] = "deviceCode";
|
|
53
|
+
AuthType["Password"] = "password";
|
|
54
|
+
AuthType["Certificate"] = "certificate";
|
|
55
|
+
AuthType["Identity"] = "identity";
|
|
56
|
+
AuthType["Browser"] = "browser";
|
|
57
|
+
AuthType["Secret"] = "secret";
|
|
59
58
|
})(AuthType || (AuthType = {}));
|
|
60
59
|
export var CertificateType;
|
|
61
60
|
(function (CertificateType) {
|
|
@@ -702,7 +701,7 @@ export class Auth {
|
|
|
702
701
|
const details = {
|
|
703
702
|
connectionName: connection.name,
|
|
704
703
|
connectedAs: connection.identityName,
|
|
705
|
-
authType:
|
|
704
|
+
authType: connection.authType,
|
|
706
705
|
appId: connection.appId,
|
|
707
706
|
appTenant: connection.tenant,
|
|
708
707
|
cloudType: CloudType[connection.cloudType]
|
package/dist/Command.js
CHANGED
|
@@ -522,7 +522,10 @@ class Command {
|
|
|
522
522
|
quote: cli.getConfig().get(settingsNames.csvQuote),
|
|
523
523
|
quoted: cli.getSettingWithDefaultValue(settingsNames.csvQuoted, false),
|
|
524
524
|
// eslint-disable-next-line camelcase
|
|
525
|
-
quoted_empty: cli.getSettingWithDefaultValue(settingsNames.csvQuotedEmpty, false)
|
|
525
|
+
quoted_empty: cli.getSettingWithDefaultValue(settingsNames.csvQuotedEmpty, false),
|
|
526
|
+
cast: {
|
|
527
|
+
boolean: (value) => value ? '1' : '0'
|
|
528
|
+
}
|
|
526
529
|
});
|
|
527
530
|
}
|
|
528
531
|
getMdOutput(logStatement, command, options) {
|
package/dist/cli/cli.js
CHANGED
|
@@ -59,6 +59,12 @@ function getSettingWithDefaultValue(settingName, defaultValue) {
|
|
|
59
59
|
return configuredValue;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
function getClientId() {
|
|
63
|
+
return cli.getSettingWithDefaultValue(settingsNames.clientId, process.env.CLIMICROSOFT365_ENTRAAPPID);
|
|
64
|
+
}
|
|
65
|
+
function getTenant() {
|
|
66
|
+
return cli.getSettingWithDefaultValue(settingsNames.tenantId, process.env.CLIMICROSOFT365_TENANT || 'common');
|
|
67
|
+
}
|
|
62
68
|
async function execute(rawArgs) {
|
|
63
69
|
const start = process.hrtime.bigint();
|
|
64
70
|
// for completion commands we also need information about commands' options
|
|
@@ -837,6 +843,11 @@ async function promptForConfirmation(config) {
|
|
|
837
843
|
await cli.error('');
|
|
838
844
|
return answer;
|
|
839
845
|
}
|
|
846
|
+
async function promptForInput(config) {
|
|
847
|
+
const answer = await prompt.forInput(config);
|
|
848
|
+
await cli.error('');
|
|
849
|
+
return answer;
|
|
850
|
+
}
|
|
840
851
|
async function handleMultipleResultsFound(message, values) {
|
|
841
852
|
const prompt = cli.getSettingWithDefaultValue(settingsNames.prompt, true);
|
|
842
853
|
if (!prompt) {
|
|
@@ -871,7 +882,9 @@ export const cli = {
|
|
|
871
882
|
closeWithError,
|
|
872
883
|
commands,
|
|
873
884
|
commandToExecute,
|
|
885
|
+
getClientId,
|
|
874
886
|
getConfig,
|
|
887
|
+
getTenant,
|
|
875
888
|
currentCommandName,
|
|
876
889
|
error,
|
|
877
890
|
execute,
|
|
@@ -890,6 +903,7 @@ export const cli = {
|
|
|
890
903
|
optionsFromArgs,
|
|
891
904
|
printAvailableCommands,
|
|
892
905
|
promptForConfirmation,
|
|
906
|
+
promptForInput,
|
|
893
907
|
promptForSelection,
|
|
894
908
|
promptForValue,
|
|
895
909
|
shouldTrimOutput,
|
package/dist/config.js
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
import { app } from
|
|
2
|
-
const cliEntraAppId = '31359c7f-bd7e-475c-86db-fdb8c937548e';
|
|
1
|
+
import { app } from './utils/app.js';
|
|
3
2
|
export default {
|
|
3
|
+
allScopes: [
|
|
4
|
+
'https://graph.windows.net/Directory.AccessAsUser.All',
|
|
5
|
+
'https://management.azure.com/user_impersonation',
|
|
6
|
+
'https://admin.services.crm.dynamics.com/user_impersonation',
|
|
7
|
+
'https://graph.microsoft.com/AppCatalog.ReadWrite.All',
|
|
8
|
+
'https://graph.microsoft.com/AuditLog.Read.All',
|
|
9
|
+
'https://graph.microsoft.com/Bookings.Read.All',
|
|
10
|
+
'https://graph.microsoft.com/Calendars.Read',
|
|
11
|
+
'https://graph.microsoft.com/ChannelMember.ReadWrite.All',
|
|
12
|
+
'https://graph.microsoft.com/ChannelMessage.Read.All',
|
|
13
|
+
'https://graph.microsoft.com/ChannelMessage.ReadWrite',
|
|
14
|
+
'https://graph.microsoft.com/ChannelMessage.Send',
|
|
15
|
+
'https://graph.microsoft.com/ChannelSettings.ReadWrite.All',
|
|
16
|
+
'https://graph.microsoft.com/Chat.ReadWrite',
|
|
17
|
+
'https://graph.microsoft.com/Directory.AccessAsUser.All',
|
|
18
|
+
'https://graph.microsoft.com/Directory.ReadWrite.All',
|
|
19
|
+
'https://graph.microsoft.com/ExternalConnection.ReadWrite.All',
|
|
20
|
+
'https://graph.microsoft.com/ExternalItem.ReadWrite.All',
|
|
21
|
+
'https://graph.microsoft.com/Group.ReadWrite.All',
|
|
22
|
+
'https://graph.microsoft.com/IdentityProvider.ReadWrite.All',
|
|
23
|
+
'https://graph.microsoft.com/InformationProtectionPolicy.Read',
|
|
24
|
+
'https://graph.microsoft.com/Mail.Read.Shared',
|
|
25
|
+
'https://graph.microsoft.com/Mail.ReadWrite',
|
|
26
|
+
'https://graph.microsoft.com/Mail.Send',
|
|
27
|
+
'https://graph.microsoft.com/Notes.ReadWrite.All',
|
|
28
|
+
'https://graph.microsoft.com/OnlineMeetingArtifact.Read.All',
|
|
29
|
+
'https://graph.microsoft.com/OnlineMeetings.ReadWrite',
|
|
30
|
+
'https://graph.microsoft.com/OnlineMeetingTranscript.Read.All',
|
|
31
|
+
'https://graph.microsoft.com/PeopleSettings.ReadWrite.All',
|
|
32
|
+
'https://graph.microsoft.com/Place.Read.All',
|
|
33
|
+
'https://graph.microsoft.com/Policy.Read.All',
|
|
34
|
+
'https://graph.microsoft.com/RecordsManagement.ReadWrite.All',
|
|
35
|
+
'https://graph.microsoft.com/Reports.Read.All',
|
|
36
|
+
'https://graph.microsoft.com/RoleAssignmentSchedule.ReadWrite.Directory',
|
|
37
|
+
'https://graph.microsoft.com/RoleEligibilitySchedule.Read.Directory',
|
|
38
|
+
'https://graph.microsoft.com/SecurityEvents.Read.All',
|
|
39
|
+
'https://graph.microsoft.com/ServiceHealth.Read.All',
|
|
40
|
+
'https://graph.microsoft.com/ServiceMessage.Read.All',
|
|
41
|
+
'https://graph.microsoft.com/ServiceMessageViewpoint.Write',
|
|
42
|
+
'https://graph.microsoft.com/Sites.Read.All',
|
|
43
|
+
'https://graph.microsoft.com/Tasks.ReadWrite',
|
|
44
|
+
'https://graph.microsoft.com/Team.Create',
|
|
45
|
+
'https://graph.microsoft.com/TeamMember.ReadWrite.All',
|
|
46
|
+
'https://graph.microsoft.com/TeamsAppInstallation.ReadWriteForUser',
|
|
47
|
+
'https://graph.microsoft.com/TeamSettings.ReadWrite.All',
|
|
48
|
+
'https://graph.microsoft.com/TeamsTab.ReadWrite.All',
|
|
49
|
+
'https://graph.microsoft.com/User.Invite.All',
|
|
50
|
+
'https://manage.office.com/ActivityFeed.Read',
|
|
51
|
+
'https://manage.office.com/ServiceHealth.Read',
|
|
52
|
+
'https://analysis.windows.net/powerbi/api/Dataset.Read.All',
|
|
53
|
+
'https://api.powerapps.com//User',
|
|
54
|
+
'https://microsoft.sharepoint-df.com/AllSites.FullControl',
|
|
55
|
+
'https://microsoft.sharepoint-df.com/TermStore.ReadWrite.All',
|
|
56
|
+
'https://microsoft.sharepoint-df.com/User.ReadWrite.All'
|
|
57
|
+
],
|
|
4
58
|
applicationName: `CLI for Microsoft 365 v${app.packageJson().version}`,
|
|
5
59
|
delimiter: 'm365\$',
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
60
|
+
configstoreName: 'cli-m365-config',
|
|
61
|
+
minimalScopes: [
|
|
62
|
+
'https://graph.microsoft.com/User.Read'
|
|
63
|
+
]
|
|
9
64
|
};
|
|
10
65
|
//# sourceMappingURL=config.js.map
|
|
@@ -2,7 +2,7 @@ import auth, { CloudType } from '../../Auth.js';
|
|
|
2
2
|
import Command, { CommandError } from '../../Command.js';
|
|
3
3
|
import { accessToken } from '../../utils/accessToken.js';
|
|
4
4
|
export default class PowerAutomateCommand extends Command {
|
|
5
|
-
get resource() {
|
|
5
|
+
static get resource() {
|
|
6
6
|
return 'https://api.flow.microsoft.com';
|
|
7
7
|
}
|
|
8
8
|
async initAction(args, logger) {
|
|
@@ -94,7 +94,7 @@ export default class SpoCommand extends Command {
|
|
|
94
94
|
catch (error) {
|
|
95
95
|
throw new CommandError(error);
|
|
96
96
|
}
|
|
97
|
-
if (auth.connection.active &&
|
|
97
|
+
if (auth.connection.active && auth.connection.authType === AuthType.Secret) {
|
|
98
98
|
throw new CommandError(`SharePoint does not support authentication using client ID and secret. Please use a different login type to use SharePoint commands.`);
|
|
99
99
|
}
|
|
100
100
|
await super.action(logger, args);
|
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _CliConsentCommand_instances, _CliConsentCommand_initTelemetry, _CliConsentCommand_initOptions, _CliConsentCommand_initValidators;
|
|
7
|
-
import
|
|
7
|
+
import { cli } from '../../../cli/cli.js';
|
|
8
8
|
import AnonymousCommand from '../../base/AnonymousCommand.js';
|
|
9
9
|
import commands from '../commands.js';
|
|
10
10
|
class CliConsentCommand extends AnonymousCommand {
|
|
@@ -26,7 +26,7 @@ class CliConsentCommand extends AnonymousCommand {
|
|
|
26
26
|
if (args.options.service === 'VivaEngage') {
|
|
27
27
|
scope = 'https://api.yammer.com/user_impersonation';
|
|
28
28
|
}
|
|
29
|
-
await logger.log(`To consent permissions for executing ${args.options.service} commands, navigate in your web browser to https://login.microsoftonline.com/${
|
|
29
|
+
await logger.log(`To consent permissions for executing ${args.options.service} commands, navigate in your web browser to https://login.microsoftonline.com/${cli.getTenant()}/oauth2/v2.0/authorize?client_id=${cli.getClientId()}&response_type=code&scope=${encodeURIComponent(scope)}`);
|
|
30
30
|
}
|
|
31
31
|
async action(logger, args) {
|
|
32
32
|
await this.initAction(args, logger);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
|
-
import auth
|
|
2
|
+
import auth from '../../../Auth.js';
|
|
3
3
|
import { cli } from '../../../cli/cli.js';
|
|
4
4
|
import Command from '../../../Command.js';
|
|
5
5
|
import { app } from '../../../utils/app.js';
|
|
@@ -33,7 +33,7 @@ class CliDoctorCommand extends Command {
|
|
|
33
33
|
nodeVersion: process.version,
|
|
34
34
|
cliAadAppId: auth.connection.appId,
|
|
35
35
|
cliAadAppTenant: validation.isValidGuid(auth.connection.tenant) ? 'single' : auth.connection.tenant,
|
|
36
|
-
authMode:
|
|
36
|
+
authMode: auth.connection.authType,
|
|
37
37
|
cliEnvironment: process.env.CLIMICROSOFT365_ENV ? process.env.CLIMICROSOFT365_ENV : '',
|
|
38
38
|
cliConfig: cli.getConfig().all,
|
|
39
39
|
roles: roles,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cli } from '../../../cli/cli.js';
|
|
2
|
-
import config from '../../../config.js';
|
|
3
2
|
import { settingsNames } from '../../../settingsNames.js';
|
|
4
3
|
import { browserUtil } from '../../../utils/browserUtil.js';
|
|
5
4
|
import AnonymousCommand from '../../base/AnonymousCommand.js';
|
|
@@ -12,9 +11,9 @@ class CliReconsentCommand extends AnonymousCommand {
|
|
|
12
11
|
return 'Returns URL to open in the browser to re-consent CLI for Microsoft 365 Microsoft Entra permissions';
|
|
13
12
|
}
|
|
14
13
|
async commandAction(logger) {
|
|
15
|
-
const url = `https://login.microsoftonline.com/${
|
|
14
|
+
const url = `https://login.microsoftonline.com/${cli.getTenant()}/oauth2/authorize?client_id=${cli.getClientId()}&response_type=code&prompt=admin_consent`;
|
|
16
15
|
if (cli.getSettingWithDefaultValue(settingsNames.autoOpenLinksInBrowser, false) === false) {
|
|
17
|
-
await logger.log(`To re-consent
|
|
16
|
+
await logger.log(`To re-consent your Microsoft Entra application, navigate in your web browser to ${url}.`);
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
19
|
await logger.log(`Opening the following page in your browser: ${url}`);
|
|
@@ -4,8 +4,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _CliConfigSetCommand_instances, _a, _CliConfigSetCommand_initTelemetry, _CliConfigSetCommand_initOptions, _CliConfigSetCommand_initValidators;
|
|
7
|
+
import { AuthType } from "../../../../Auth.js";
|
|
7
8
|
import { cli } from "../../../../cli/cli.js";
|
|
8
9
|
import { settingsNames } from "../../../../settingsNames.js";
|
|
10
|
+
import { validation } from "../../../../utils/validation.js";
|
|
9
11
|
import AnonymousCommand from "../../../base/AnonymousCommand.js";
|
|
10
12
|
import commands from "../../commands.js";
|
|
11
13
|
class CliConfigSetCommand extends AnonymousCommand {
|
|
@@ -34,7 +36,6 @@ class CliConfigSetCommand extends AnonymousCommand {
|
|
|
34
36
|
case settingsNames.printErrorsAsPlainText:
|
|
35
37
|
case settingsNames.prompt:
|
|
36
38
|
case settingsNames.showHelpOnFailure:
|
|
37
|
-
case settingsNames.showSpinner:
|
|
38
39
|
value = args.options.value === 'true';
|
|
39
40
|
break;
|
|
40
41
|
default:
|
|
@@ -82,15 +83,22 @@ _a = CliConfigSetCommand, _CliConfigSetCommand_instances = new WeakSet(), _CliCo
|
|
|
82
83
|
cli.helpModes.indexOf(args.options.value) === -1) {
|
|
83
84
|
return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${cli.helpModes.join(', ')}`;
|
|
84
85
|
}
|
|
85
|
-
const allowedAuthTypes = ['certificate', 'deviceCode', 'password', 'identity', 'browser', 'secret'];
|
|
86
86
|
if (args.options.key === settingsNames.authType &&
|
|
87
|
-
|
|
88
|
-
return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${
|
|
87
|
+
!Object.values(AuthType).map(String).includes(args.options.value)) {
|
|
88
|
+
return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${Object.values(AuthType).join(', ')}`;
|
|
89
89
|
}
|
|
90
90
|
if (args.options.key === settingsNames.helpTarget &&
|
|
91
91
|
!cli.helpTargets.includes(args.options.value)) {
|
|
92
92
|
return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${cli.helpTargets.join(', ')}`;
|
|
93
93
|
}
|
|
94
|
+
if (args.options.key === settingsNames.clientId &&
|
|
95
|
+
!validation.isValidGuid(args.options.value)) {
|
|
96
|
+
return `${args.options.value} is not a valid value for the option ${args.options.key}. The value has to be a valid GUID.`;
|
|
97
|
+
}
|
|
98
|
+
if (args.options.key === settingsNames.tenantId &&
|
|
99
|
+
!(args.options.value === 'common' || validation.isValidGuid(args.options.value))) {
|
|
100
|
+
return `${args.options.value} is not a valid value for the option ${args.options.key}. The value has to be a valid GUID or 'common'.`;
|
|
101
|
+
}
|
|
94
102
|
return true;
|
|
95
103
|
});
|
|
96
104
|
};
|
|
@@ -3,13 +3,12 @@ import { z } from 'zod';
|
|
|
3
3
|
import auth, { AuthType, CloudType } from '../../Auth.js';
|
|
4
4
|
import Command, { CommandError, globalOptionsZod } from '../../Command.js';
|
|
5
5
|
import { cli } from '../../cli/cli.js';
|
|
6
|
-
import config from '../../config.js';
|
|
7
6
|
import { settingsNames } from '../../settingsNames.js';
|
|
8
7
|
import { zod } from '../../utils/zod.js';
|
|
9
8
|
import commands from './commands.js';
|
|
10
9
|
const options = globalOptionsZod
|
|
11
10
|
.extend({
|
|
12
|
-
authType: zod.alias('t', z.
|
|
11
|
+
authType: zod.alias('t', z.nativeEnum(AuthType).optional()),
|
|
13
12
|
cloud: z.nativeEnum(CloudType).optional().default(CloudType.Public),
|
|
14
13
|
userName: zod.alias('u', z.string().optional()),
|
|
15
14
|
password: zod.alias('p', z.string().optional()),
|
|
@@ -37,6 +36,9 @@ class LoginCommand extends Command {
|
|
|
37
36
|
}
|
|
38
37
|
getRefinedSchema(schema) {
|
|
39
38
|
return schema
|
|
39
|
+
.refine(options => typeof options.appId !== 'undefined' || cli.getConfig().get(settingsNames.clientId), {
|
|
40
|
+
message: `appId is required. TIP: use the "m365 setup" command to configure the default appId`
|
|
41
|
+
})
|
|
40
42
|
.refine(options => options.authType !== 'password' || options.userName, {
|
|
41
43
|
message: 'Username is required when using password authentication',
|
|
42
44
|
path: ['userName']
|
|
@@ -49,11 +51,17 @@ class LoginCommand extends Command {
|
|
|
49
51
|
message: 'Specify either certificateFile or certificateBase64Encoded, but not both.',
|
|
50
52
|
path: ['certificateBase64Encoded']
|
|
51
53
|
})
|
|
52
|
-
.refine(options => options.authType !== 'certificate' ||
|
|
54
|
+
.refine(options => options.authType !== 'certificate' ||
|
|
55
|
+
options.certificateFile ||
|
|
56
|
+
options.certificateBase64Encoded ||
|
|
57
|
+
cli.getConfig().get(settingsNames.clientCertificateFile) ||
|
|
58
|
+
cli.getConfig().get(settingsNames.clientCertificateBase64Encoded), {
|
|
53
59
|
message: 'Specify either certificateFile or certificateBase64Encoded',
|
|
54
60
|
path: ['certificateFile']
|
|
55
61
|
})
|
|
56
|
-
.refine(options => options.authType !== 'secret' ||
|
|
62
|
+
.refine(options => options.authType !== 'secret' ||
|
|
63
|
+
options.secret ||
|
|
64
|
+
cli.getConfig().get(settingsNames.clientSecret), {
|
|
57
65
|
message: 'Secret is required when using secret authentication',
|
|
58
66
|
path: ['secret']
|
|
59
67
|
});
|
|
@@ -64,13 +72,24 @@ class LoginCommand extends Command {
|
|
|
64
72
|
await logger.logToStderr(`Logging out from Microsoft 365...`);
|
|
65
73
|
}
|
|
66
74
|
const deactivate = () => auth.connection.deactivate();
|
|
75
|
+
const getCertificate = (options) => {
|
|
76
|
+
// command args take precedence over settings
|
|
77
|
+
if (options.certificateFile) {
|
|
78
|
+
return fs.readFileSync(options.certificateFile).toString('base64');
|
|
79
|
+
}
|
|
80
|
+
if (options.certificateBase64Encoded) {
|
|
81
|
+
return options.certificateBase64Encoded;
|
|
82
|
+
}
|
|
83
|
+
return cli.getConfig().get(settingsNames.clientCertificateFile) ||
|
|
84
|
+
cli.getConfig().get(settingsNames.clientCertificateBase64Encoded);
|
|
85
|
+
};
|
|
67
86
|
const login = async () => {
|
|
68
87
|
if (this.verbose) {
|
|
69
88
|
await logger.logToStderr(`Signing in to Microsoft 365...`);
|
|
70
89
|
}
|
|
71
90
|
const authType = args.options.authType || cli.getSettingWithDefaultValue(settingsNames.authType, 'deviceCode');
|
|
72
|
-
auth.connection.appId = args.options.appId ||
|
|
73
|
-
auth.connection.tenant = args.options.tenant ||
|
|
91
|
+
auth.connection.appId = args.options.appId || cli.getClientId();
|
|
92
|
+
auth.connection.tenant = args.options.tenant || cli.getTenant();
|
|
74
93
|
auth.connection.name = args.options.connectionName;
|
|
75
94
|
switch (authType) {
|
|
76
95
|
case 'password':
|
|
@@ -80,9 +99,9 @@ class LoginCommand extends Command {
|
|
|
80
99
|
break;
|
|
81
100
|
case 'certificate':
|
|
82
101
|
auth.connection.authType = AuthType.Certificate;
|
|
83
|
-
auth.connection.certificate =
|
|
102
|
+
auth.connection.certificate = getCertificate(args.options);
|
|
84
103
|
auth.connection.thumbprint = args.options.thumbprint;
|
|
85
|
-
auth.connection.password = args.options.password;
|
|
104
|
+
auth.connection.password = args.options.password ?? cli.getConfig().get(settingsNames.clientCertificatePassword);
|
|
86
105
|
break;
|
|
87
106
|
case 'identity':
|
|
88
107
|
auth.connection.authType = AuthType.Identity;
|
|
@@ -93,7 +112,7 @@ class LoginCommand extends Command {
|
|
|
93
112
|
break;
|
|
94
113
|
case 'secret':
|
|
95
114
|
auth.connection.authType = AuthType.Secret;
|
|
96
|
-
auth.connection.secret = args.options.secret;
|
|
115
|
+
auth.connection.secret = args.options.secret || cli.getConfig().get(settingsNames.clientSecret);
|
|
97
116
|
break;
|
|
98
117
|
}
|
|
99
118
|
auth.connection.cloudType = args.options.cloud;
|