代码之家  ›  专栏  ›  技术社区  ›  Riccardo Malesani

Adobe Analytics将API认证问题与节点分割开来。js客户端

  •  0
  • Riccardo Malesani  · 技术社区  · 7 年前

    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+'"'
         }
    };
    

    如您所见,我试图复制API Explorer生成的x-wsse,通过Date()JS类动态指定创建的timestap。 节点客户端正在向我报告此错误:
    {“error”:“错误请求”,“error\u描述”:“无法验证身份验证。”,“error\u uri”:null}

    如果这就是问题的原因,那么如何在x-wsse标头中动态插入这些参数?

    谢谢。

    1 回复  |  直到 7 年前
        1
  •  2
  •   CrayonViolent    7 年前

    是的 PasswordDigest Created 值也是动态生成的,因为它们基于您生成的值。我不知道节点。js足以显示一个节点。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\""));