oauth - OVH API Authentication with powershell -
i'm trying list of dedicated servers hosted @ ovh using powershell, via new spangly api. i'm bit stuck @ generating authentication signature. think followed steps here: https://api.ovh.com/g934.first_step_with_api guess messed up. script far looks this:
$applicationkey = 'myappkey' $applicationsecret = 'myappsecret' function makeapirequest($url, $method, $body = $null) { $timestamp = (invoke-webrequest 'https://eu.api.ovh.com/1.0/auth/time').content $consumerkey = getconsumerkey $hashinput = "$applicationsecret+$consumerkey+$method+$url+$(if($body -eq $null) { ''} else { $body })+$timestamp" write-host "hashinput $hashinput" $hashstream = new-object system.io.memorystream(,[system.text.encoding]::utf8.getbytes($hashinput)) $hash = (get-filehash -inputstream $hashstream -algorithm sha1).hash.tolower() write-host "hash $hash" $headers = @{ 'x-ovh-application' = $applicationkey; 'x-ovh-signature' = $hash; 'x-ovh-consumer' = $consumerkey; 'x-ovh-timestamp' = $timestamp } return invoke-webrequest -method $method -uri $url -body $body -headers $headers -contenttype 'application/json' } function getconsumerkey() { $body = @{ accessrules = @( @{ method = 'get'; path = '/*' } ); redirection = 'http://crispthinking.com' } $headers = @{ 'x-ovh-application' = $applicationkey } $response = (invoke-webrequest -method post -uri 'https://eu.api.ovh.com/1.0/auth/credential' -body $($body | convertto-json) -headers $headers -contenttype 'application/json') | convertfrom-json return $response.consumerkey } $result = makeapirequest -url 'https://eu.api.soyoustart.com/1.0/dedicated/server/' -method 'get' however response looks this:
http/1.1 400 bad request date: mon, 11 may 2015 12:08:25 gmt server: apache/2.2.20 (unix) mod_ssl/2.2.20 openssl/0.9.8o mod-xslt/1.3.9 x-ovh-queryid: fr.ws-2.55509bb9.27183.3172 cache-control: no-cache access-control-allow-origin: * connection: close content-type: application/json; charset=utf-8 content-length: 92 {"errorcode":"invalid_signature","httpcode":"400 bad request","message":"invalid signature"} can see flaw in script?
i think 've forgoten prepend $1$ signature.
"$1$" + sha1_hex(as+"+"+ck+"+"+method+"+"+query+"+"+body+"+"+tstamp)
Comments
Post a Comment