0

我正在尝试通过他们新的 spangly API 获取使用 powershell 托管在 OVH 的专用服务器列表。但我有点卡在生成身份验证签名上。我我遵循了这里的步骤:https ://api.ovh.com/g934.first_step_with_api但我想我搞砸了。到目前为止,我的脚本如下所示:

$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 is $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 is $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'

但是,我得到的回复如下所示:

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

任何人都可以看到脚本中的缺陷吗?

4

1 回答 1

1

我认为您忘记在签名前添加 $1$。

"$1$" + SHA1_HEX(AS+"+"+CK+"+"+METHOD+"+"+QUERY+"+"+BODY+"+"+TSTAMP)
于 2015-05-11T13:30:33.387 回答