DUO API - Code 40101 Missing Request Credentials - Powershell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 07:02 AM
Would anybody be able to help me out here? Having problems connecting to the DUO api in powershell, i think it is to do with the headers but cannot figure out what is wrong???
function ConvertTo-Base64($string)
{
$bytes = [System.Text.Encoding]::UTF8.GetBytes($string);
$encoded = [System.Convert]::ToBase64String($bytes);
return $encoded;
}
$intKey = “integrationkey”
$sKey = “secretkey”
$hostname = “hostname”
$path = “/auth/v2/check”
$params = $null
$method = “GET”
$contentType = “application/x-www-form-urlencoded”
$day = (get-date).day
$dayAbr = (get-date).DayOfWeek.ToString().Substring(0,3)
$month = (get-date).Month
$monthAbr = (Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($month)
$year = (get-date).Year
$time = (get-date).TimeOfDay
[string]$date = $dayAbr + “, " + $day + " " + $monthAbr + " " + $year + " " + $time.Hours + “:” + $time.Minutes + “:” + $time.Seconds + " -0000”
message = ($date + “n" + $method + "
n” + $hostname + “n" + $path + "
n”)
$secret = $sKey
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($secret)
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($message))
$signature = [Convert]::ToBase64String($signature)
$b64 = ConvertTo-Base64($intKey + “:” + $signature);
$auth = "Basic " + $signature;
$headers = @{}
$headers.Add(“Date”, $date)
$headers.Add(“Authorization”, $auth)
$headers.Add(“Host”, $hostname)
$headers.Add(“Content-Length”, “35”)
$headers.Add(“Content-Type”, $contentType)
Invoke-WebRequest -Uri $(“https://” + $hostname + $command) -Headers $headers
- Labels:
-
API - General

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 02:50 PM
Check out this function I created that will create a properly formatted request
https://github.com/StarkCaptain/duo/blob/master/scripts/new-duoRequest.ps1
$Request = New-DuoRequest -apiHost ‘■■■■’ -apiEndpoint ‘/admin/v1/users’ -apiKey ‘nnnnn’ -apiSecret ‘nnnnn’
Invoke-RestMethod @Request
Its forked from the below module, however I didn’t prefer how the author assumes certain things about how you store the api secret so I re-wrote it a bit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:54 PM
I tried the module but i get this error. Verified the integration Key and secret key. Is there something I am missing?
Invoke-RestMethod : {“code”: 40102, “message”: “Invalid integration key in request credentials”, “stat”: “FAIL”}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 07:21 PM
I am still using that powershell function as is today. Do you have the admin api application setup with the necessary API permissions based on the api endpoints you want to use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 09:26 AM
I believe I do but I am new to DUO so is there anything I should look for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 01:37 AM
Hi This is Yuri
do you know how to call api with powershell?
BR

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 05:43 PM
what is message = ($date + “n" + $method + “n” + $hostname + “n” + $path + "n”)
$secret = $sKey
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($secret)
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($message))
$signature = [Convert]::ToBase64String($signature)
$b64 = ConvertTo-Base64($intKey + “:” + $signature);
$auth = "Basic " + $signature;?? do we still need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2021 09:59 AM
Just want to verify that this function worked for me. You can test it by calling the function as described in the comments at the top. Thanks! — L
