Invoke-WebRequest with digest

See original GitHub issue

We have a script that runs just fine on Powershell 5, but when executing on devops agenst running ubuntu and powershell core 7.1 it always fails with a 401 Error.

$Password = ConvertTo-SecureString $MongoAtlasApiKeyPrivate -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($MongoAtlasApiKeyPublic, $Password)

Invoke-WebRequest -Uri $MongoAtlasApiUrl -Method POST -ContentType "application/json" -Credential $Credentials -Body $json

It’s trying to callt he mongo atlas api, which according to mongo’s documentation requires digest authentictaion. However I couldn’t find anything mentioning digest with Invoke-WebRequest. Onlny Oauth and other auth methods, but nothing about digest. Is it just no possible anymore since PWSH 6/7?

This is the corresponding mongo documentation: https://docs.atlas.mongodb.com/reference/api/whitelist-add-one

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
CarloTosocommented, Feb 10, 2023

@iSazonov I think we can close, the issue underlying with dotnet was fixed, It works correctly in PS7.3.2 Test:

$password = ConvertTo-SecureString 'password' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ('user', $password)
Invoke-WebRequest "https://httpbin.org/digest-auth/auth/user/password" -Credential $credential
0reactions
msftbot[bot]commented, Feb 11, 2023

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to use digest authentication with invoke- ...
I've been trying to find some reference to doing this but I haven't been able to find anything besides the chilkat reference.
Read more >
View topic - [SOLVED]Powershell restful authentication
I'm trying to use Powershell to access one or two things via the API. I'm using. Code: Select all: Invoke-WebRequest -URL $url -credential...
Read more >
Use Invoke-WebRequest with a username and password ...
Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API · $pair should be $pair = "$($user):$($pass)" Check ...
Read more >
Invoke-WebRequest - PowerShell
The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of...
Read more >
Using PowerShell Invoke-RestMethod with REST APIs
The Invoke-RestMethod and Invoke-WebRequest functions of PowerShell allow easy interactions with an API and aid in creating complex workflows.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found