Arrange header params in PHP - php

I am working in header authorization in plain PHP to arrange given results.
In any way i try to arrange them with
$headers=array(
'Authorization:'Signature,
'Content-Type: application/json'
);
but nothing seems to be working.
And the result I need to arrange is:
Authorization: Signature keyId="57502612d1bb2c0001000025fd53850cd9a94861507a5f7cca236882",algorithm="hmac-sha1",headers="date x-mod-nonce",signature="WBMr%2FYdhysbmiIEkdTrf2hP7SfA%3D"

Related

How to get Header & data-raw Of Curl Response from PHP

Using third party service; they are providing webhook services; I have given my url to send the response on my page:
Example: https://abcd.com/postback.php
Getting curl response on postback.php; to read the POST data; I am using following code:
$postdata = file_get_contents("php://input");
but not able to read the header & data content.
Sample Response that they are sending:
curl -L -X POST 'https://abcd.com/postback.php' -H 'x-changenow-signature: xcgh123POPI6727kslsldjsd' -H 'Content-Type: application/json' --data-raw '{"status":"finished","payinHash":"31mrEanXyv","payoutHash":"485d8dz","payinAddress":"3Nups0bF","payoutAddress":"1K1LcQSPZVj2dM","fromCurrency":"sol","toCurrency":"btc","amountSend":0.06676453,"amountReceive":0.00010273,"refundAddress":"Bk1qVzc3GULcJQ0NoW4DsepRJHevzAD8ynznEQ1aNzGq","id":"f7bed8a9e4a350","updatedAt":"2022-06-23T11:22:38.728Z","createdAt":"2022-06-23T11:09:56.403Z","expectedReceiveAmount":0.0001024,"isPartner":false}
Please suggest how to get header and data part.
The headers are in $_SERVER. Use $_SERVER['HTTP_X_CHANGENOW_SIGNATURE'] to get the x-changenow-signature header.
The data content is in $postdata. Use
$data = json_decode($postdata);
to convert it to an object. Then you can use $data->status, $data->payinHash, etc. to get the fields of the post data.

Correct way to calculate the content-length of an associative array in PHP

Is the below the correct way to calculate the content-length of an associative array to POST in PHP CURL?
$contentLength = strlen(json_encode($myAssocArray)); // is this correct??
...
$headers = array(
'Content-Type: application/json',
"Content-length: $contentLength"
);
I am getting HTTP 100 responses back which makes me think that my content-length is wrong. Note, I know CURL can auto calulate the content length header but if I don't include this header for the server I am sending this to they send back a HTTP 411 (Length Required) response.

Upload data using selling-partner-api in Amazon using PHP

I have successfully encrypted the required parameters, but I am posting the data to this URL
https://tortuga-prod-na.s3-external-1.amazonaws.com/%2FNinetyDays/amzn1.tortuga.3.xxxxx-xxx-xxxx-xxx-xxxxxxx.xxxxx
Drops me this error AuthorizationHeaderMalformedThe authorization header is malformed; incorrect service "execute-api". This endpoint belongs to "s3".9DD75A286E7422B6rxCxNZ3veB/3ZJ1qrtvleA0JaHTPqprLYe3I5mM/LYLLEVPL6iKGv0irGmV1O9SS4AcmPsM/8/I=
$headers = [
'Content-Type: text/plain; charset=utf-8',
'X-Amz-Content-Sha256: UNSIGNED-PAYLOAD',
'X-Amz-Date: 20210105T095435Z',
'Authorization: AWS4-HMAC-SHA256 Credential={ access-key-when-create-IAM }/20210105/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-access-token;x-amz-content-sha256;x-amz-date, Signature={generated through auth process}',
];
I have lost no idea what's wrong. Any help will be appreciated.
Change service from 'execute-api' to 's3'

Authorization header is not passing in php curl is use CURLOPT_HTTPHEADER

I have come around a strange issue that when I am passing authorization header like below,
CURLOPT_HTTPHEADER => array(
"Authorization: Basic XXXXXXXXXX",
"Content-Type: application/json",
),
If I send like this then Authorization is not showing in request header.
But If I have Auth details like below,
CURLOPT_USERPWD=>"xxxxx:xxxxxx",
it will adding required Authorization header as I needed in htpp request.
So what is the issue in this? why it is not simply work as given in first code snippet? Also I am not able to send custom header, custom headers are also not available in request body.

Basic Authorization using CURL and Fastbill API

i'm having a hard time authorizing a user login since i just dont know the right syntax. I want to modify https://github.com/ZWEISCHNEIDER/fastbill to enable said login API-wise.
The current header bit looks like this and works
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'header' => 'Authorization: Basic ' . base64_encode($this->email.':'.$this->apiKey)
)
);
With this i can connect to the general API and get all the information. In the documentation of the API it requires me to put the following additional info into the header (left -u line there for better understanding) in order to receive user-bound information only.
-u {E-Mail-Address}:{API-Key} \
-H 'X-Username: {User-Emailaddress}'\
-H 'X-Password: {User-Password}' \
How do i adapt the 'header' content-string to fit X-Username:$username and X-Password:$pwd in there?
(api doc: https://www.fastbill.com/api/fastbill/en/fundamentals.html#authentification)
thanks in advance
ok i'm sorry, this did not have anything to do with malformed header requests from my side -- the api simply won't let me access like i planned using a regular api key

Categories