Skip to content

Commit

Permalink
Updated warnings for using -Interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvanhunen committed Sep 9, 2024
1 parent a251584 commit a44a161
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/Commands/Base/ConnectOnline.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.SharePoint.Client;
using Microsoft.Graph;
using Microsoft.SharePoint.Client;
using PnP.Framework;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Enums;
Expand Down Expand Up @@ -352,7 +353,7 @@ protected void Connect(ref CancellationToken cancellationToken)
if (AzureEnvironment == AzureEnvironment.Custom)
{
SetCustomEndpoints();
}
}

// Connect using the used set parameters
switch (ParameterSetName)
Expand Down Expand Up @@ -399,7 +400,7 @@ protected void Connect(ref CancellationToken cancellationToken)
case ParameterSet_OSLOGIN:
newConnection = ConnectWithOSLogin();
break;
}
}

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

// Connection has been established
WriteVerbose($"Connected");

if (newConnection.Url != null)
{
var hostUri = new Uri(newConnection.Url);
Expand Down Expand Up @@ -572,11 +573,12 @@ private PnPConnection ConnectDeviceLogin()
}
else
{
clientId = PnPConnection.PnPManagementShellClientId;
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 });
//clientId = PnPConnection.PnPManagementShellClientId;
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 });
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
}
}

var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, LaunchBrowser, messageWriter, AzureEnvironment, cancellationTokenSource);
connection = returnedConnection;
messageWriter.Finished = true;
Expand Down Expand Up @@ -706,8 +708,9 @@ private PnPConnection ConnectCredentials(PSCredential credentials, Initializatio
}
else
{
ClientId = PnPConnection.PnPManagementShellClientId;
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 });
// ClientId = PnPConnection.PnPManagementShellClientId;
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 });
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
}
}

Expand Down Expand Up @@ -772,8 +775,9 @@ private PnPConnection ConnectInteractive()
}
else
{
ClientId = PnPConnection.PnPManagementShellClientId;
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 });
//ClientId = PnPConnection.PnPManagementShellClientId;
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 });
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
}
}
if (Connection?.ClientId == ClientId && Connection?.ConnectionMethod == ConnectionMethod.Credentials)
Expand Down Expand Up @@ -841,7 +845,8 @@ private PnPConnection ConnectEnvironmentVariable(InitializationType initializati
if (string.IsNullOrEmpty(azureClientId))
{
azureClientId = PnPConnection.PnPManagementShellClientId;
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 });
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 });
ThrowTerminatingError(new ErrorRecord(new NotSupportedException(), "PNPMGTSHELLNOTSUPPORTED", ErrorCategory.AuthenticationError, this));
}

SecureString secPassword = StringToSecureString(password);
Expand Down Expand Up @@ -895,7 +900,7 @@ private PnPConnection ConnectWithOSLogin()
ReuseAuthenticationManager();
}
}

WriteVerbose($"Using ClientID {ClientId}");

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

0 comments on commit a44a161

Please sign in to comment.