0

I am able to connect fine to azure API's using a PAT token in postman, however am not able to authenticate using powershell.

After playing around with different authorization passing I am still stuck with getting the html page for the sign in returned. Here is a sample request I am making

Invoke-RestMethod https://feeds.dev.azure.com/xx/x/_apis/packaging/Feeds/x/Packages -Headers @{Authorization="Token :xxx"}
J.Doe
  • 155
  • 1
  • 9

1 Answers1

0

After much searching I came across https://www.opentechguides.com/how-to/article/azure/201/devops-rest-powershell.html. Here is a simplified snippet that allowed my request to go through successfully.

#enter your token in pat token
$pat = "xxx"

# Create header with PAT
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$header = @{authorization = "Basic $token"}

#enter your url in projects url
$projectsUrl = "https://feeds.dev.azure.com/xx/x/_apis/packaging/Feeds/x/Packages -Headers"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers $header
J.Doe
  • 155
  • 1
  • 9