Skip to content

Commit

Permalink
Fixed Google now enforcing application/x-www-form-urlencoded content
Browse files Browse the repository at this point in the history
This OAuth2Client class is now compliant with the RFC6749 specifications (https://tools.ietf.org/html/rfc6749#section-2.3.1) regarding POST requests.
  • Loading branch information
imsamthomas authored Dec 13, 2016
1 parent 441992f commit 8f8a839
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Hybrid/thirdparty/OAuth/OAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ private function request( $url, $params=false, $type="GET" )
Logger::info( "Enter OAuth2Client::request( $url )" );
Logger::debug( "OAuth2Client::request(). dump request params: ", serialize( $params ) );

$urlEncodedParams = http_build_query($params, '', '&');

if( $type == "GET" ){
$url = $url . ( strpos( $url, '?' ) ? '&' : '?' ) . http_build_query($params, '', '&');
$url = $url . ( strpos( $url, '?' ) ? '&' : '?' ) . $urlEncodedParams;
}

$this->http_info = array();
Expand All @@ -235,7 +237,12 @@ private function request( $url, $params=false, $type="GET" )

if( $type == "POST" ){
curl_setopt($ch, CURLOPT_POST, 1);
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, $params );

// Using URL encoded params here instead of a more convenient array
// cURL will set a wrong HTTP Content-Type header if using an array (cf. http://www.php.net/manual/en/function.curl-setopt.php, Notes section for "CURLOPT_POSTFIELDS")
// OAuth requires application/x-www-form-urlencoded Content-Type (cf. https://tools.ietf.org/html/rfc6749#section-2.3.1)
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, $urlEncodedParams);

}
if( $type == "DELETE" ){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
Expand Down

0 comments on commit 8f8a839

Please sign in to comment.