PowerShell/PowerShellGet

Connecting to protected AzureDevops devops artifact feed.

sdixon-a23 opened this issue · 3 comments

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

I'm trying to connect from PowerShell to a protected feed in Azure DevOps - hoping to avoid using PAT. I want users to be able to SSO and connect to feed and pull-down PowerShell modules.

I'm using CredentialProvider.Microsoft.exe to get and save the creds of the user.

Sample code:

Install-Module -Name PsResourceGet -AllowPrerelease -Force
Install-Module -Name Microsoft.PowerShell.PSResourceGet -AllowPrerelease -Force
Install-Module SecretManagement.JustinGrote.CredMan


Import-Module Microsoft.PowerShell.SecretManagement  -Force -Verbose
Import-Module Microsoft.Powershell.PsResourceGet  -Force -Verbose

Register-SecretVault -Name MyOrg -ModuleName SecretManagement.JustinGrote.CredMan

Get-PSResourceRepository

Unregister-PSResourceRepository -Name "MyDevOpsFeed"

$packageLocation = "https://pkgs.dev.azure.com/myorg/myproject/_packaging/myfeed/nuget/v3/index.json"

$vssCredentialProvider = "$env:UserProfile\.nuget\plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe"

$tokenJson = ConvertFrom-Json (& $vssCredentialProvider -U $packageLocation -F Json)

$pscred = new-object System.Management.Automation.PSCredential -ArgumentList $tokenJson.Username, (ConvertTo-SecureString $tokenJson.Password -AsPlainText -Force)

Get-SecretInfo -Name MyPsFeed -Vault MyOrg | Remove-Secret

Set-Secret -Name MyPsFeed -Vault MyOrg -Secret $pscred

Get-SecretInfo -Name MyPsFeed -Vault MyOrg

$credentialInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo("MyOrg", "MyPsFeed")

$params = @{
    Name = 'MyDevOpsFeed'
    Uri  = $packageLocation
     Trusted = $true
     CredentialInfo = $credentialInfo
}

Register-PSResourceRepository @params

Set-PSResourceRepository -Name MyDevOpsFeed -ApiVersion v3

Get-PSResourceRepository

Find-PSResource -Name Hello-World -Repository MyDevOpsFeed

Install-PSResource -Repository "MyDevOpsFeed" -Name Hello-World

The result is 'Response status code does not indicate success: 401 (Unauthorized).' Re-run the command with -Credential

If I change Find-PSResource -Name Hello-World -Repository MyDevOpsFeed to Find-PSResource -Name Setup-Git -Repository MyDevOpsFeed -Credential $credentialInfo I get the error Cannot bind parameter 'Credential'. Cannot convert the value of type "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo" to type "System.Management.Automation.PSCredential".

If I change Find-PSResource -Name Hello-World -Repository MyDevOpsFeed to Find-PSResource -Name Setup-Git -Repository MyDevOpsFeed -Credential $pscred I get the error

WARNING: Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.
Install-PSResource: .\connect.ps1:46:1
Line |
46 | Install-PSResource -Repository "MyDevOpsFeed" -Name Setup-Git -Cred …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 'Response status code does not indicate success: 401 (Unauthorized).' Re-run the command with -Credential.

One thing woth noting, in the examples I have read they use a type Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo, I cannot seem to resolve this. I can however find Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo

Expected behavior

Module installed

Actual behavior

Response status code does not indicate success: 401 (Unauthorized).' Re-run the command with -Credential

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

latest

Visuals

No response

now how do I undo what I just copied into my powershell serously I try to find a fix for an error on google and it took me here and it did not fix it I cant seem to find anything relevent to what I serch on google any more why is that did eddie poo thretting to rip all the eyes out if they let me know something because of a guy who peeled of my face in 2013 and wor it barked some messed up words at him or what the f

the inter net has turned r tarded

you used to be able to search and find but now what