Authentication issue using api_key

Hello,

I’m getting an 401 unauthorized when I try to POST the body with the authentication information to {{host}}/api/2.0/admin/auth/tokens
Considering that I don’t have a token jet to authenticate against the system, I’m not sure what I need to do.
I followed: https://splynx.docs.apiary.io/#reference/auth/tokens/generate-access-token

Hey all,
just as a reference, I found my issue,
The hash was generated wrong in PowerShell here is the working code:

$aaaserver = "https://yourserver/api/2.0/"
$aaakey = "removed"
$aaasecret = "removed"
$aaanonce = ([Math]::Floor([decimal](Get-Date(Get-Date).ToUniversalTime()-uformat "%s"))).ToString()


$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($aaasecret)
$aaamessage = $aaanonce + $aaakey
$aaasignature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($aaamessage))
#$aaasignature = [Convert]::ToBase64String($aaasignature)
$aaasignature = [System.BitConverter]::ToString($aaasignature) -replace '-', ''
$aaasignature = $aaasignature.ToUpper()

$aaaauthpage = $aaaserver + "admin/auth/tokens"

$jsonRequest = [ordered]@{
    auth_type="api_key"
    key=$aaakey
    signature=$aaasignature
    nonce=$aaanonce
    } 
$json = $jsonRequest | ConvertTo-Json -Depth 2

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", 'application/json')
$headers.Add("Accept", 'application/json')

$response = Invoke-RestMethod $aaaauthpage -Method 'POST' -Headers $headers -Body $json
$response | ConvertTo-Json
1 Like