OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.38k stars 190 forks source link

Install-Module from VSTS PSRepository with Credential fails. #350

Open bmanikm opened 6 years ago

bmanikm commented 6 years ago

From @jwittner on April 12, 2018 21:37

Note: The same commands succeed in Windows Powershell.

Steps to reproduce

$creds = Get-Credential #Enter VSTS PAT
Register-PSRepository -Name <feed> -SourceLocation <feed url>
Install-Module <module> -Repository <feed> -Credential $creds -Scope CurrentUser

Expected behavior

Package would install.

Actual behavior

WARNING: Source Location 'https://<account>.pkgs.visualstudio.com/_packaging/<feed>/nuget/v2?id=<module>&version=<version>' is not valid.
PackageManagement\Install-Package : Package '<module>' failed to download.
At C:\program files\powershell\6.0.2\Modules\PowerShellGet\1.6.0\PSModule.psm1:2057 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (C:\<userfolder>\<module>.nupkg:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.2
PSEdition                      Core
GitCommitId                    v6.0.2
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Copied from original issue: PowerShell/PowerShellGet#261

bmanikm commented 6 years ago

@jwittner please take a look at https://github.com/PowerShell/PowerShell-Docs/issues/1200#issue-227526581 for more details on installing from a VSTS feed with PAT. Is this only applicable to PowerShell Core? If it is still reproducible, can you please provide the debug output of Install-Module?

bmanikm commented 6 years ago

From @jwittner on April 17, 2018 0:5

I had left a small note at the top of my issue, but to clarify this does function in Windows PowerShell, it only fails in Core. I've attached the debug output logs.

bmanikm commented 6 years ago

@jwittner thanks for the debug log. It looks like this issue is happening in NuGet provider. I am moving this to http://GitHub.com\OneGet\OneGet repo.

InstallPackage' - name='build', version='3.2.4888',destination='C:\Users\jowitt\AppData\Local\Temp\1726031933'
DownloadPackage' - name='build', version='3.2.4888',destination='C:\Users\jowitt\AppData\Local\Temp\1726031933\build\build.nupkg', uri='https://wwhs.pkgs.visualstudio.com/_packaging/wwhs.powershell/nuget/v2?id=build&version=3.2.4888'
Downloading 'https://wwhs.pkgs.visualstudio.com/_packaging/wwhs.powershell/nuget/v2?id=build&version=3.2.4888'.
Object reference not set to an instance of an object.
00:00:06.3406939    at System.Net.Http.WinHttpAuthHelper.SaveServerCredentialsToCache(Uri uri, UInt32 authScheme, ICredentials serverCredentials)
   at System.Net.Http.WinHttpAuthHelper.CheckResponseForAuthentication(WinHttpRequestState state, UInt32& proxyAuthScheme, UInt32& serverAuthScheme)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PackageManagement.NuGetProvider.NuGetClient.<DownloadDataToFileAsync>d__15.MoveNext()
nblumhardt commented 5 years ago

Unrelated project, but, we've just debugged the same NullReferenceException in our own NuGet v3 client (also triggered by VSTS/PATs, and crashing on the same line).

We inspected the corefx code (WinHttpAuthHelper) but couldn't spot anything obviously to blame.

In the end, we worked around it by setting PreAuthenticate = false on our HttpClientHandler - we can now install packages from VSTS feeds using PATs 🎉

Not sure if the same thing will work here, but might be worth investigating. HTH!