【问题标题】:401 Permission Error with Balanced Payments平衡付款的 401 权限错误
【发布时间】:2014-07-13 10:51:16
【问题描述】:

我正在使用 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"
    }
  ]

【问题讨论】:

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


    【解决方案1】:
    "Authorization"  : balancedSecret
    

    这将是错误的。您使用秘密作为用户名,而没有任何东西作为密码。然后将它们连接在一起,对它们进行 base64 编码,并将 that 作为 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);
    
          }
    });
    

    【讨论】:

      猜你喜欢
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 2018-04-12
      相关资源
      最近更新 更多