ios - 平衡支付的 401 权限错误

标签 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"
    }
  ]

最佳答案

"Authorization"  : balancedSecret

这是错误的。您使用 secret 作为用户名,没有任何内容作为密码。然后将它们连接在一起,对它们进行 base64 编码,并将 that 作为 auth header 的值传递。

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

"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);

      }
});

关于ios - 平衡支付的 401 权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721888/

相关文章:

ios - WatchOS 应用程序 4.0 : How to schedule a local notification

http - 为 Jboss 管理控制台 URL 配置 HTTP header

http - 面向服务的架构 - 传输层(http 与消息传递)

ios - 生成不重复的随机 UIImage

ios - 将 CNContact 保存在 UserDefaults 中

ios - ARC下sharedInstance模式的内存含义是什么?

ios - 无法上传 iOS 模拟器版本以供 Facebook 应用审查

ios - ImagePickerController 裁剪问题

http - 创建框架重定向会导致 Chrome 抛出 X-Frame-Options 错误

ios - UIAlertView 运行模式