Skip to content

Commit b59e7a6

Browse files
Merge pull request #5167 from pnp/PR5116
Pr5116
2 parents 09e83e8 + 07882fe commit b59e7a6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Commands/Base/ConnectOnline.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ private PnPConnection ConnectDeviceLogin()
572572
Tenant = TenantExtensions.GetTenantIdByUrl(Url, AzureEnvironment);
573573
}
574574

575-
var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, messageWriter, AzureEnvironment, cancellationTokenSource, PersistLogin, Host);
575+
var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, messageWriter, AzureEnvironment, cancellationTokenSource, PersistLogin, Host, ErrorActionSetting);
576576
connection = returnedConnection;
577577
messageWriter.Finished = true;
578578
}
@@ -790,7 +790,7 @@ private PnPConnection ConnectInteractive()
790790
}
791791
}
792792
LogDebug($"Using ClientID {ClientId}");
793-
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false, PersistLogin, Host);
793+
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false, PersistLogin, Host, ErrorActionSetting);
794794
}
795795

796796
private PnPConnection ConnectEnvironmentVariable(InitializationType initializationType = InitializationType.EnvironmentVariable)
@@ -932,7 +932,7 @@ private PnPConnection ConnectWithOSLogin()
932932
{
933933
WriteObject("Cache used. Clear the cache entry with Disconnect-PnPOnline");
934934
}
935-
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true, PersistLogin, Host);
935+
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true, PersistLogin, Host, ErrorActionSetting);
936936
}
937937

938938
private PnPConnection ConnectFederatedIdentity()

src/Commands/Base/PnPConnection.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ internal PnPContext PnPContext
164164
internal PnP.Framework.AuthenticationManager AuthenticationManager { get; set; }
165165

166166
private string _graphEndPoint;
167-
167+
/// <summary>
168+
private static readonly string[] errorActionSourceArray = ["stop", "ignore", "silentlycontinue"];
168169
#endregion
169170

170171
#region Creators
@@ -258,15 +259,18 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string
258259
return spoConnection;
259260
}
260261

261-
internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, string tenantId, CmdletMessageWriter messageWriter, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool persistLogin, System.Management.Automation.Host.PSHost host)
262+
internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, string tenantId, CmdletMessageWriter messageWriter, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool persistLogin, System.Management.Automation.Host.PSHost host, string ErrorActionSetting = null)
262263
{
263264
if (persistLogin)
264265
{
265266
EnableCaching(url, clientId);
266267
}
267268
if (CacheEnabled(url, clientId))
268269
{
269-
WriteCacheEnabledMessage(host);
270+
if (!errorActionSourceArray.Contains(ErrorActionSetting.ToLowerInvariant()))
271+
{
272+
WriteCacheEnabledMessage(host);
273+
}
270274
}
271275
var connectionUri = new Uri(url);
272276
var scopes = new[] { $"{connectionUri.Scheme}://{connectionUri.Authority}//.default" }; // the second double slash is not a typo.
@@ -468,15 +472,18 @@ internal static PnPConnection CreateWithManagedIdentity(string url, string tenan
468472
}
469473
}
470474

471-
internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCredential credentials, bool currentCredentials, string tenantAdminUrl, bool persistLogin, System.Management.Automation.Host.PSHost host, AzureEnvironment azureEnvironment = AzureEnvironment.Production, string clientId = null, string redirectUrl = null, bool onPrem = false, InitializationType initializationType = InitializationType.Credentials)
475+
internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCredential credentials, bool currentCredentials, string tenantAdminUrl, bool persistLogin, System.Management.Automation.Host.PSHost host, AzureEnvironment azureEnvironment = AzureEnvironment.Production, string clientId = null, string redirectUrl = null, bool onPrem = false, InitializationType initializationType = InitializationType.Credentials, string ErrorActionSetting = null)
472476
{
473477
if (persistLogin)
474478
{
475479
EnableCaching(url.ToString(), clientId);
476480
}
477481
if (CacheEnabled(url.ToString(), clientId))
478482
{
479-
WriteCacheEnabledMessage(host);
483+
if (!errorActionSourceArray.Contains(ErrorActionSetting.ToLowerInvariant()))
484+
{
485+
WriteCacheEnabledMessage(host);
486+
}
480487
}
481488
var context = new PnPClientContext(url.AbsoluteUri)
482489
{
@@ -588,15 +595,18 @@ internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCr
588595
return spoConnection;
589596
}
590597

591-
internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientId, string tenantAdminUrl, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool forceAuthentication, string tenant, bool enableLoginWithWAM, bool persistLogin, System.Management.Automation.Host.PSHost host)
598+
internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientId, string tenantAdminUrl, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool forceAuthentication, string tenant, bool enableLoginWithWAM, bool persistLogin, System.Management.Automation.Host.PSHost host, string ErrorActionSetting)
592599
{
593600
if (persistLogin)
594601
{
595602
EnableCaching(uri.ToString(), clientId);
596603
}
597604
if (CacheEnabled(uri.ToString(), clientId))
598605
{
599-
WriteCacheEnabledMessage(host);
606+
if (!errorActionSourceArray.Contains(ErrorActionSetting.ToLowerInvariant()))
607+
{
608+
WriteCacheEnabledMessage(host);
609+
}
600610
}
601611

602612
var htmlMessageSuccess = "<html lang=en><meta charset=utf-8><title>PnP PowerShell - Sign In</title><meta content=\"width=device-width,initial-scale=1\"name=viewport><style>html{height:100%}.message-container{flex-grow:1;display:flex;align-items:center;justify-content:center;margin:0 30px}body{box-sizing:border-box;min-height:100%;display:flex;flex-direction:column;color:#fff;font-family:\"Segoe UI\",\"Helvetica Neue\",Helvetica,Arial,sans-serif;background-color:#2c2c32;margin:0;padding:15px 30px}.message{font-weight:300;font-size:1.4rem}.branding{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAYAAAC3g3x9AAAABHNCSVQICAgIfAhkiAAABhhJREFUSIl1lXuMVHcVxz/3d+/MnXtnX8PudqmyLx672+WtCKWx8irUloKJtY2xsdmo1T9MWmM0Go0JarEoRSQh6R8KFRuiVm3RSAMSCsijsmWXx2KB3QWW2cfszs7uPO7M3DtzHz//QJoA4Zucf84535PvyUnOFx4Ay7JW2bb9muu6Jz3Ps13XLZZKpUO5XO7xB3EeiLGxMdN13fcymbS8g4nxhAyCQBYKBd+27Z89iKvdmxgYGNDr6+v/6ZbLazzXo1Qq0fvhWVKTSTo651NbVy/ylvUTx3H0SCTyg3v5yr0Jx3F+q2naN4ZuXCeTSXPovYMsXLQIx3aYTk0yPZXi5e/9EDMalbZtvxiNRvcDKIoi75NbKBS+EARBIKWUvee65Ttv/0levHBBFosFeePGdTkyHJc7f/WaHOy/JqWU0vO8UmpysmhZ1rfvW/nmzZsRXdd32batpNPTjI2M0DF/AT2953l9xw5SqSnWrl3LU09v4sL5HurqHyKdSYcbG5umUqnU7+9b2XGc7+i6vhPg9L+PUx2rZWBwkG3bfommaRiRCJlslsWLFvKlZ7+IGY2yavUapJQyl8str6mpOQcgAI4dO6ZpmvZdgGwmjWGaqJrGzp2/oaOjg1/v2MGevXvYuPFpLvX1cehfRwg8FykliqIo0Wj0R3eECYAVK1ZsUlW1sVgocObkCVrnzGX79tcByZqVy/jbG9v4/gvPoPs2j3S0c+rUKT661s++vb+jWCygqurmdDrd/P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yD0ObnGXd0suks8fgIuXyB6uoqNE1rzGQyjXd5im3bXbquv3ns5GnePXiE1uZGntv8eYS423qEEIRCIRQUNE0jWhEFyaWtW7cuvasxn88vDILAKxaLMpvLSitvSc/zPg7f9+X/LUdKKWUQBIHnedlyubwvmUzOvMsC7qBYLD4XCoV+rChKi5QyEQTBP3zfHxdCiCAIPEVRMr7vJwqFwmAul7P2798/tWXLluAO/38rUwksVQPdogAAAABJRU5ErkJggg==);background-repeat:no-repeat;padding-left:26px;font-size:20px;letter-spacing:-.04rem;font-weight:400;height:26px;color:#fff;background-position:left center;text-decoration:none}</style><a class=branding href=https://pnp.github.io/powershell>PnP PowerShell</a><div class=message-container><div class=message>You are signed in now and can close this page.</div></div>";

0 commit comments

Comments
 (0)