平衡付款的401权限错误

时间:2014-07-13 10:51:17

标签: ios objective-c http parse-platform balanced-payments

我正在使用Parse.Cloud.httpRequest,我需要发送基本身份验证,只使用用户名进行平衡付款。这是怎么回事?看起来会是什么样的?我尝试在标题中设置它,但这不起作用。

 Parse.Cloud.httpRequest({
          method:'POST',
          url: customerUrl,
          headers:{
            "Content-Type"      : "application/x-www-form-urlencoded",
               "Accept"         : "application/vnd.api+json;revision=1.1",
               "Authorization"  : balancedSecret
          },
          body:bodyJsonString,
          success: function(httpResponse) {
            console.log(httpResponse.text);
            response.success(httpResponse.text);
          },
          error: function(httpResponse) {
            console.error('Request failed with response code ' + httpResponse.status);
            response.error(httpResponse.text);

          }
    });

当我调用我得到的功能时:

"errors": [
    {
      "status": "Unauthorized",
      "category_code": "authentication-required",
      "description": "Not permitted to perform create on customers. Your request id is OHMca9c440a0a7811e4ba9202a1fe52a36c.",
      "status_code": 401,
      "category_type": "permission",
      "request_id": "OHMca9c440a0a7811e4ba9202a1fe52a36c"
    }
  ]

1 个答案:

答案 0 :(得分:2)

"Authorization"  : balancedSecret

这将是错误的。您使用密码作为用户名,而没有密码。然后将它们连接在一起,base64对它们进行编码,并将 作为auth标头的值传递。

我没有设置来仔细检查这个,但这应该作为值:

"Basic " + encodeBase64(balancedSecret + ":")

提供此代码:

authHeader = "Basic " + btoa(balancedSecret + ":")
Parse.Cloud.httpRequest({
      method:'POST',
      url: customerUrl,
      headers:{
        "Content-Type"      : "application/x-www-form-urlencoded",
           "Accept"         : "application/vnd.api+json;revision=1.1",
           "Authorization"  : authHeader
      },
      body:bodyJsonString,
      success: function(httpResponse) {
        console.log(httpResponse.text);
        response.success(httpResponse.text);
      },
      error: function(httpResponse) {
        console.error('Request failed with response code ' + httpResponse.status);
        response.error(httpResponse.text);

      }
});