sscarpa / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

CURLOPT_POSTFIELDS resets Content-Type header #68

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It appears that some time this afternoon, Google's OAuth2 pages suddenly became 
more strict, as my unmodified checkout of this library stopped working.

While attempting to login using OAuth2, the library was throwing an 
apiAuthException (400 error -- "Invalid content type specified in the 
request"). Searching for the error on Google returned nothing.

After hours of digging, I discovered a problem with apiCurlIO::makeRequest(). 
$postBody is declared as an array, and is assigned to CURLOPT_POSTFIELDS as 
such. When this happens, PHP forces a 'Content-type: multipart/form-data' 
header. This results is the above error from the Google OAuth2 Token page.

I added code to my checkout to process the array into a string and urlencode() 
the parameters. Functionality was successfully restored.

I would like to see some form of this fix added to the project.

====================
Original trashed response is below:

Fatal error: Uncaught exception 'apiAuthException' with message 'Error fetching 
OAuth2 access token, message: '<HTML> <HEAD> <TITLE>Invalid content type 
specified in the request</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" 
TEXT="#000000"> <H1>Invalid content type specified in the request</H1> 
<H2>Error 400</H2> </BODY> </HTML> '' in 
/home/brandon/projects/chefhangout/sys/modules/google/auth/apiOAuth2.php:104 
Stack trace: #0 
/home/brandon/projects/chefhangout/sys/modules/google/apiClient.php(131): 
apiOAuth2->authenticate(Array) #1 
/home/brandon/projects/chefhangout/sys/modules/google/public/oauth-callback.php(
21): apiClient->authenticate() #2 
/home/brandon/projects/chefhangout/router.php(90): 
include_once('/home/brandon/p...') #3 {main} thrown 
in/home/brandon/projects/chefhangout/sys/modules/google/auth/apiOAuth2.phpon 
line 104

Original issue reported on code.google.com by trip.som...@gmail.com on 17 Jan 2012 at 11:38

GoogleCodeExporter commented 8 years ago
There was a post about this on the mailing list.  
https://groups.google.com/d/msg/google-api-php-client/piRpF0s0WS0/LETQ4ARj308J

There was an issue in how the Content-Type header was and should be fixed in 
production right now. It stopped accepting anything other than '"Content-Type: 
application www-form-urlencoded" earlier today.

I also quickly published a new version of the client library that works around 
this issue as soon as I learned about it.  It is available here:
http://code.google.com/p/google-api-php-client/downloads/detail?name=google-api-
php-client-0.4.8.3.tar.gz

Original comment by chirags@google.com on 18 Jan 2012 at 3:24

GoogleCodeExporter commented 8 years ago

Original comment by chirags@google.com on 18 Jan 2012 at 5:41