Skip to content

Commit 7640802

Browse files
stloydOrliaguet Mylene
authored andcommitted
Fixed LinkedIn resource owner to always put Content-Length header in POST reqeusts : cherry pick 859ec55
1 parent 74d2c7e commit 7640802

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

OAuth/ResourceOwner/AbstractResourceOwner.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ protected function httpRequest($url, $content = null, array $headers = [], $meth
248248
$method = null === $content || '' === $content ? 'GET' : 'POST';
249249
}
250250

251-
$headers += array('User-Agent' => 'HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)');
252-
if (is_string($content)) {
253-
$headers += array('Content-Length' => (string) strlen($content));
254-
} elseif (is_array($content)) {
251+
$headers += ['User-Agent' => 'HWIOAuthBundle (https://github.com/hwi/HWIOAuthBundle)'];
252+
if (\is_string($content)) {
253+
if (!isset($headers['Content-Length'])) {
254+
$headers += ['Content-Length' => (string) \strlen($content)];
255+
}
256+
} elseif (\is_array($content)) {
255257
$content = http_build_query($content, '', '&');
256258
}
257259

OAuth/ResourceOwner/LinkedinResourceOwner.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ protected function doGetTokenRequest($url, array $parameters = [])
7373
*/
7474
protected function httpRequest($url, $content = null, array $headers = [], $method = null)
7575
{
76-
// Linkedin v2 API is supposed to require Content-Type: application/json but it works without
76+
// LinkedIn v2 API is supposed to require Content-Type: application/json but it works without
7777
// and request to get the access token doesn't seems to work with Content-Type: application/json
7878
// so we don't put any Content-Type header.
7979
// Skip the Content-Type header in GenericOAuth2ResourceOwner::httpRequest
80+
//
81+
// LinkedIn API requires to always set Content-Length in POST requests
82+
if ('POST' === $method) {
83+
$headers['Content-Length'] = \is_string($content) ? (string) \strlen($content) : '0';
84+
}
85+
8086
return AbstractResourceOwner::httpRequest($url, $content, $headers, $method);
8187
}
8288

0 commit comments

Comments
 (0)