Skip to content

Commit a44a161

Browse files
committed
Updated warnings for using -Interactive
1 parent a251584 commit a44a161

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/Commands/Base/ConnectOnline.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.SharePoint.Client;
1+
using Microsoft.Graph;
2+
using Microsoft.SharePoint.Client;
23
using PnP.Framework;
34
using PnP.PowerShell.Commands.Base.PipeBinds;
45
using PnP.PowerShell.Commands.Enums;
@@ -352,7 +353,7 @@ protected void Connect(ref CancellationToken cancellationToken)
352353
if (AzureEnvironment == AzureEnvironment.Custom)
353354
{
354355
SetCustomEndpoints();
355-
}
356+
}
356357

357358
// Connect using the used set parameters
358359
switch (ParameterSetName)
@@ -399,7 +400,7 @@ protected void Connect(ref CancellationToken cancellationToken)
399400
case ParameterSet_OSLOGIN:
400401
newConnection = ConnectWithOSLogin();
401402
break;
402-
}
403+
}
403404

404405
// Ensure a connection instance has been created by now
405406
if (newConnection == null)
@@ -410,7 +411,7 @@ protected void Connect(ref CancellationToken cancellationToken)
410411

411412
// Connection has been established
412413
WriteVerbose($"Connected");
413-
414+
414415
if (newConnection.Url != null)
415416
{
416417
var hostUri = new Uri(newConnection.Url);
@@ -572,11 +573,12 @@ private PnPConnection ConnectDeviceLogin()
572573
}
573574
else
574575
{
575-
clientId = PnPConnection.PnPManagementShellClientId;
576-
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "You are authenticating using the PnP Management Shell multi-tenant App Id. It is strongly recommended to register your own Entra ID App for authentication. See the documentation for Register-PnPEntraIDApp.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
576+
//clientId = PnPConnection.PnPManagementShellClientId;
577+
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "Connecting with -DeviceLogin used the PnP Management Shell multi-tenant App Id for authentication. As of September 9th, 2024 this option is not available anymore. Refer to https://pnp.github.io/powershell/articles/registerapplication.html on how to register your own application.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
578+
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
577579
}
578580
}
579-
581+
580582
var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, LaunchBrowser, messageWriter, AzureEnvironment, cancellationTokenSource);
581583
connection = returnedConnection;
582584
messageWriter.Finished = true;
@@ -706,8 +708,9 @@ private PnPConnection ConnectCredentials(PSCredential credentials, Initializatio
706708
}
707709
else
708710
{
709-
ClientId = PnPConnection.PnPManagementShellClientId;
710-
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "You are authenticating using the PnP Management Shell multi-tenant App Id. It is strongly recommended to register your own Entra ID App for authentication. See the documentation for Register-PnPEntraIDApp.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
711+
// ClientId = PnPConnection.PnPManagementShellClientId;
712+
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "As of September 9th, 2024 the option to use the PnP Management Shell app registration for authentication is not available anymore. Refer to https://pnp.github.io/powershell/articles/registerapplication.html on how to register your own application.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
713+
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
711714
}
712715
}
713716

@@ -772,8 +775,9 @@ private PnPConnection ConnectInteractive()
772775
}
773776
else
774777
{
775-
ClientId = PnPConnection.PnPManagementShellClientId;
776-
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "Connecting with -Interactive uses the PnP Management Shell multi-tenant App Id for authentication. It is strongly recommended to register your own Entra ID App for authentication. See the documentation for Register-PnPEntraIDAppForInteractiveLogin.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
778+
//ClientId = PnPConnection.PnPManagementShellClientId;
779+
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "Connecting with -Interactive used the PnP Management Shell multi-tenant App Id for authentication. As of September 9th, 2024 this option is not available anymore. Refer to https://pnp.github.io/powershell/articles/registerapplication.html on how to register your own application.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
780+
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
777781
}
778782
}
779783
if (Connection?.ClientId == ClientId && Connection?.ConnectionMethod == ConnectionMethod.Credentials)
@@ -841,7 +845,8 @@ private PnPConnection ConnectEnvironmentVariable(InitializationType initializati
841845
if (string.IsNullOrEmpty(azureClientId))
842846
{
843847
azureClientId = PnPConnection.PnPManagementShellClientId;
844-
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "You are authenticating using the PnP Management Shell multi-tenant App Id. It is strongly recommended to register your own Entra ID App for authentication. See the documentation for Register-PnPEntraIDApp.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
848+
CmdletMessageWriter.WriteFormattedMessage(this, new CmdletMessageWriter.Message { Text = "Connecting without an Azure Client ID used then PnP Management Shell multi-tenant App Id for authentication. As of September 9th, 2024 this option is not available anymore. Refer to https://pnp.github.io/powershell/articles/registerapplication.html on how to register your own application.", Formatted = true, Type = CmdletMessageWriter.MessageType.Warning });
849+
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
845850
}
846851

847852
SecureString secPassword = StringToSecureString(password);
@@ -895,7 +900,7 @@ private PnPConnection ConnectWithOSLogin()
895900
ReuseAuthenticationManager();
896901
}
897902
}
898-
903+
899904
WriteVerbose($"Using ClientID {ClientId}");
900905

901906
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, LaunchBrowser, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true);

0 commit comments

Comments
 (0)