I'm using Parse.Cloud.httpRequest and I need to send basic authentication with only a username to balanced payments. Where does this go and what would that look like? I tried setting it in the Headers but that's not working.
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);
}
});
When I call the function I get:
"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
This is going to be wrong. You use the secret as the username, and nothing as the password. You then concatenate them together, base64 encode them, and pass that as the value of the auth header.
I don't have the setup to double check this, but this should work as the value:
"Basic " + encodeBase64(balancedSecret + ":")
Giving this code:
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);
}
});