pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

Set-PnpContext does not completely switch to previously saved context #2817

Open Choggo opened 4 years ago

Choggo commented 4 years ago

Reporting an Issue or Missing Feature

Set-PnpContext isn't completly switching to a previously saved context

This issue affects other commands such as New-PnPUnifiedGroup

Expected behavior

When running the reproduction commands, I would expect the Graph access token to be printed to the console.

Actual behavior

Connect-PnPOnline -Scopes to connect.
At line:10 char:1
+ Get-PnPGraphAccessToken
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (:) [Get-PnPGraphAccessToken], InvalidOperationException
    + FullyQualifiedErrorId : NO_OAUTH_TOKEN,SharePointPnP.PowerShell.Commands.Base.GetGraphAccessToken

Steps to reproduce behavior

Connect-PnPOnline -Url $url -ClientId $GraphAppId -ClientSecret $GraphAppSecret
$AppContext = Get-PnpContext

Connect-PnPOnline -Url $url -Credentials $userCredential
$AdminContext = Get-PnpContext
Set-PnPContext -Context $AppContext

Get-PnPGraphAccessToken

Reversing the order of creating the connections bypasses the issue, but there's no way of knowing if it'll break something else.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name sharepointpnppowershell* -ListAvailable)

3.23.2007.1

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

Choggo commented 4 years ago

Reading through the code, I do see that Set-PnpContext only replaces the current clientcontext and not the connection as a whole.

Is the behavior I described something intended then?