Skip to content

Commit

Permalink
Merge pull request pnp#4586 from pnp/PR4585
Browse files Browse the repository at this point in the history
Pr4585
  • Loading branch information
erwinvanhunen authored Nov 28, 2024
2 parents 3c8c9fa + 118812e commit 9ad7e02
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 28 deletions.
17 changes: 13 additions & 4 deletions src/Commands/Base/ConnectOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ public class ConnectOnline : BasePSCmdlet
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_OSLOGIN)]
public SwitchParameter OSLogin;


[Parameter(Mandatory = false, ParameterSetName = ParameterSet_INTERACTIVE)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_DEVICELOGIN)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_OSLOGIN)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_CREDENTIALS)]
public SwitchParameter PersistLogin;

private static readonly string[] sourceArray = ["stop", "ignore", "silentlycontinue"];

protected override void ProcessRecord()
Expand Down Expand Up @@ -765,8 +772,7 @@ private PnPConnection ConnectInteractive()
}
}
WriteVerbose($"Using ClientID {ClientId}");

return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false);
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false, PersistLogin, Host);
}

private PnPConnection ConnectEnvironmentVariable(InitializationType initializationType = InitializationType.EnvironmentVariable)
Expand Down Expand Up @@ -902,8 +908,11 @@ private PnPConnection ConnectWithOSLogin()
}

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

return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true);
if (PnPConnection.CacheEnabled(Url, ClientId))
{
WriteObject("Cache used. Clear the cache entry with Disconnect-PnPOnline");
}
return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true, PersistLogin, Host);
}

#endregion
Expand Down
9 changes: 9 additions & 0 deletions src/Commands/Base/DisconnectOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace PnP.PowerShell.Commands.Base
[OutputType(typeof(void))]
public class DisconnectOnline : PSCmdlet
{

[Parameter(Mandatory = false)]
public SwitchParameter ClearPersistedLogin;

protected override void ProcessRecord()
{
if (PnPConnection.Current == null)
Expand All @@ -30,6 +34,11 @@ protected override void ProcessRecord()
PnPConnection.Current.Certificate = null;
}

if(ClearPersistedLogin)
{
PnPConnection.ClearCache(PnPConnection.Current);
}

PnPConnection.Current = null;

var provider = SessionState.Provider.GetAll().FirstOrDefault(p => p.Name.Equals(SPOProvider.PSProviderName, StringComparison.InvariantCultureIgnoreCase));
Expand Down
Loading

0 comments on commit 9ad7e02

Please sign in to comment.