aliyun / aliyun/openapi-sdk-php
ROA Request invalid signature : resolveBody never add Content-MD5 if isset $this->options['body']
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 530
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
- PHP Version:
- 8.1
- Platform:
- Magento 2.4.6
- Product:
- CloudAPI
- Product Version:
- 2016-07-14
- API:
- ROA request
original code: got error invalid signature because Content-MD5 never add to headers in resolveParameter.
$req = AlibabaCloud::roa()
->product('CloudAPI')
->version('2016-07-14')
->host($this->config('host'))
->pathPattern($this->config('path'))
->scheme('https')
->options(['headers' =>['Content-Type'=>'application/json']])
->method('POST')
->body($body)
->debug(1);
$req->resolveParameter();
$res = $req->request();
fixed by below: add Content-MD5 myself
$req = AlibabaCloud::roa()
->product('CloudAPI')
->version('2016-07-14')
->host($this->config('host'))
->pathPattern($this->config('path'))
->scheme('https')
->options(['headers' =>
['Content-Type'=>'application/json','Content-MD5' => base64_encode(hex2bin(md5($body)))]])
->method('POST')
->body($body)
->debug(1);
$req->resolveParameter();
$res = $req->request();
what I found:
/vendor/alibabacloud/client/src/Request/RoaRequest.php
private function resolveBody()
{
// If the body has already been specified, it will not be resolved.
if (isset($this->options['body'])) {
return;
}
......
}
should be :
private function resolveBody()
{
// If the body has already been specified, it will not be resolved.
if (isset($this->options['body'] )
&& Stringy::contains($this->options['headers']['Content-Type'], 'application/json')
) {
$this->options['headers']['Content-MD5'] = base64_encode(hex2bin(md5($this->options['body'], true)));
return;
}
......
}
BTW:
you are using : ===> not try yet
base64_encode(md5($this->options['body'], true));
I am using: ===> it works
base64_encode(hex2bin(md5($body)))
Line 101:
if (Stringy::contains($this->options['headers']['Content-Type'], 'application/json', false)) {
should be:
if (Stringy::contains($this->options['headers']['Content-Type'], 'application/json')) {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in vendor/alibabacloud/client/src/Request/RoaRequest.php, focusing on resolveBody() and the Content-Type check around line 101. Reproduce the POST ROA request with a body, then verify that Content-MD5 is added and the signature is accepted without manually supplying the header.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100