Powershell Invoke-RestMethod Authorization Header

Reddipalle Nagarjun picture Reddipalle Nagarjun · Jan 15, 2019 · Viewed 10k times · Source

While invoking an Invoke-RestMethod using Powershell like:

Invoke-RestMethod -Method Get -Uri "https://google.com/api/GetData" -Headers $headers

and $headers being

$headers = @{
    Authorization="Secret $username $password"
    Content='application/json'
}

What is the format expected for the parameters $username and $password?

Answer

rufer7 picture rufer7 · Jan 16, 2019

As far as I know you have to send a OAuth2 token in the request headers.

$headers = @{
    Authorization="Bearer $token"
}

Perhaps the following blog post gives you an idea how to do so. https://lazyadmin.nl/it/connect-to-google-api-with-powershell/