@pnp/cli-microsoft365 10.0.0-beta.48e9f7d → 10.0.0-beta.e925c1c

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/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 = config.cliEntraAppId;
48
- this.tenant = config.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[AuthType["DeviceCode"] = 0] = "DeviceCode";
54
- AuthType[AuthType["Password"] = 1] = "Password";
55
- AuthType[AuthType["Certificate"] = 2] = "Certificate";
56
- AuthType[AuthType["Identity"] = 3] = "Identity";
57
- AuthType[AuthType["Browser"] = 4] = "Browser";
58
- AuthType[AuthType["Secret"] = 5] = "Secret";
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: AuthType[connection.authType],
704
+ authType: connection.authType,
706
705
  appId: connection.appId,
707
706
  appTenant: connection.tenant,
708
707
  cloudType: CloudType[connection.cloudType]
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 "./utils/app.js";
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
- cliEntraAppId: process.env.CLIMICROSOFT365_ENTRAAPPID || cliEntraAppId,
7
- tenant: process.env.CLIMICROSOFT365_TENANT || 'common',
8
- configstoreName: 'cli-m365-config'
60
+ configstoreName: 'cli-m365-config',
61
+ minimalScopes: [
62
+ 'https://graph.microsoft.com/User.Read'
63
+ ]
9
64
  };
10
65
  //# sourceMappingURL=config.js.map
@@ -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 && AuthType[auth.connection.authType] === AuthType[AuthType.Secret]) {
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 config from '../../../config.js';
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/${config.tenant}/oauth2/v2.0/authorize?client_id=${config.cliEntraAppId}&response_type=code&scope=${encodeURIComponent(scope)}`);
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, { AuthType } from '../../../Auth.js';
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: AuthType[auth.connection.authType],
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/${config.tenant}/oauth2/authorize?client_id=${config.cliEntraAppId}&response_type=code&prompt=admin_consent`;
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 the PnP Microsoft 365 Management Shell Microsoft Entra application navigate in your web browser to ${url}`);
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 {
@@ -82,15 +84,22 @@ _a = CliConfigSetCommand, _CliConfigSetCommand_instances = new WeakSet(), _CliCo
82
84
  cli.helpModes.indexOf(args.options.value) === -1) {
83
85
  return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${cli.helpModes.join(', ')}`;
84
86
  }
85
- const allowedAuthTypes = ['certificate', 'deviceCode', 'password', 'identity', 'browser', 'secret'];
86
87
  if (args.options.key === settingsNames.authType &&
87
- allowedAuthTypes.indexOf(args.options.value) === -1) {
88
- return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${allowedAuthTypes.join(', ')}`;
88
+ !Object.values(AuthType).map(String).includes(args.options.value)) {
89
+ return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${Object.values(AuthType).join(', ')}`;
89
90
  }
90
91
  if (args.options.key === settingsNames.helpTarget &&
91
92
  !cli.helpTargets.includes(args.options.value)) {
92
93
  return `${args.options.value} is not a valid value for the option ${args.options.key}. Allowed values: ${cli.helpTargets.join(', ')}`;
93
94
  }
95
+ if (args.options.key === settingsNames.clientId &&
96
+ !validation.isValidGuid(args.options.value)) {
97
+ return `${args.options.value} is not a valid value for the option ${args.options.key}. The value has to be a valid GUID.`;
98
+ }
99
+ if (args.options.key === settingsNames.tenantId &&
100
+ !(args.options.value === 'common' || validation.isValidGuid(args.options.value))) {
101
+ 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'.`;
102
+ }
94
103
  return true;
95
104
  });
96
105
  };
@@ -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.enum(['certificate', 'deviceCode', 'password', 'identity', 'browser', 'secret']).optional()),
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' || options.certificateFile || options.certificateBase64Encoded, {
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' || options.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 || config.cliEntraAppId;
73
- auth.connection.tenant = args.options.tenant || config.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 = args.options.certificateBase64Encoded ? args.options.certificateBase64Encoded : fs.readFileSync(args.options.certificateFile, 'base64');
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;