cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5286
Views
0
Helpful
7
Replies

DUO API - Code 40101 Missing Request Credentials - Powershell

kieron25
Level 1
Level 1

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

7 Replies 7

Toto_Tamberine
Level 1
Level 1

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.

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”}

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?

I believe I do but I am new to DUO so is there anything I should look for?

Hi This is Yuri

do you know how to call api with powershell?

BR

kabuchan15
Level 1
Level 1

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?

lkeyes1
Level 1
Level 1

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

Quick Links