2017-07-24 57 views
0

我正面臨嘗試通過node.js客戶端使用細分API的授權問題。 停止旁敲側擊,它的部分,低於該管理POST請求,並通過X-WSSE頭的授權:使用node.js客戶端的Adobe Analytics細分API驗證問題

var now = new Date(); 
var options = { 
    method: "POST", 
    hostname: "api3.omniture.com", 
    path: "/admin/1.4/rest/?method=Segments.Get", 
    json: true, 
    headers: { 
      "Content-Type": "application/json", 
      "Content-Length" : Buffer.byteLength(JSON.stringify(body)), 
      "x-wsse": 'UsernameToken Username="[username]:[company]", PasswordDigest="xxxxxxxxxxxxxxxxxxxxxxxxxx==", Nonce="yyyyyyyyyyyyyyyyyyyyyyyyyy", Created="'+now+'"' 
    } 
}; 

正如你看到的,我試圖通過複製產生的x WSSE API Explorer,通過Date()JS類動態指定Created timestap。 節點客戶端報告我這個錯誤:
{「錯誤」:「錯誤的請求」,「ERROR_DESCRIPTION」:「無法驗證身份驗證」,「error_uri」:空}

我想的x wsse PasswordDigest和Nonce值也會在每個請求中不斷更改,而在這裏我將它們設置爲靜態。 如果這是問題的原因,那麼如何動態地將這些參數插入到x-wsse頭文件中?

非常感謝。

回答

2

是的,PasswordDigestCreated值也是動態生成的,因爲它們基於您生成的值。我不知道node.js的足夠好,你展示Node.js的例子,但這裏是我做的一個PHP的例子,有一些意見:

$username='user:company'; 
$secret='12345'; // api shared secret key for the user 
// The nonce should be a universally unique value. I use a timestamp based value and prefix with a namespace to help make it unique, because AA request digests have to be unique across everybody everywhere ever 
$nonce = 'FOO_'.dechex(time()); 
// datetime stamp in ISO 8601 date format (e.g. '2004-02-12T15:19:21+00:00') 
$nonce_ts = date('c'); 
// Adobe expects the PasswordDigest to be a concatenated string value of the nonce, datetimestamp, and api key. They expect it to be hashed (sha1) and then base64 encoded 
$digest = base64_encode(sha1($nonce.$nonce_ts.$secret)); 
$server = "https://api.omniture.com"; 
$path = "/admin/1.4/rest/"; 
$rc=new SimpleRestClient(); 
$rc->setOption(CURLOPT_HTTPHEADER, array("X-WSSE: UsernameToken Username=\"$username\", PasswordDigest=\"$digest\", Nonce=\"$nonce\", Created=\"$nonce_ts\"")); 
+0

@RiccardoMalesani順便說一句看起來像Adobe確實有[節點sdk](https://github.com/Adobe-Marketing-Cloud/marketing-cloud-node-sdk),可能有助於參考(或只是使用..不知道你的最終境況是什麼!) –