Greetings,
Greetings I'm using the OAuth 2.0 log-in module to allow users to login to my website and so I can get some basic information (name, email, locality). I'm using the Web Server approach to processing the authorization request. Perhaps I'm making this all too complicated but here's where I'm at, and why I'm doing it this way:
First, I've tried to implement the "
Google APIs Client Library for PHP" to use the pre-built class first, but came to impasse because of the apiClient::setDeveloperKey(); property. At least, I think that's where the hangup was, because I read in
the help documentation that:
"However, if your application already uses an OAuth 2.0 access token,
then there is no need to generate an API key as well. In fact, Google
ignores passed API keys if an OAuth 2.0 access token is already
associated with the corresponding project."
If I'm total reading this wrong, I'd be open to exploring this option again, but have abandoned it for the moment.
Here's how I've chosen to proceed. I am able to successfully receive the Authorization Code back from the OAuth framework. However, I'm having trouble forming the POST request to get the authorization token. Right now, I am getting this response back from the OAuth server:
string(387) "HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Mon, 06 Aug 2012 14:35:32 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
{
"error" : "invalid_request"
}"
I'm suspecting the issue is with the way that I've assembled the CURL request (as this is new to me), but not sure.
Here's the string that I'm sending:
?code=4/jCjsHJScBDkGMikD-BHJntaW5Q8t.wpfikJZY_yoVuJJVnL49Cc_UHL34cQI&client_id=316688784512.apps.googleusercontent.com&client_secret=**********************&redirect_uri=http://example.com/alpha/patron/check-in/google/auth&grant_type=authorization_code
Here's how I'm assembling the CURL request (not sure about all these settings):
$cg = curl_init('https://accounts.google.com/o/oauth2/token');
curl_setopt($cg, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cg, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cg, CURLOPT_FAILONERROR, false);
curl_setopt($cg, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($cg, CURLOPT_HEADER, true);
curl_setopt($cg, CURLOPT_POST, true);
curl_setopt($cg, CURLOPT_POSTFIELDS, $cg_fields);
//curl_setopt($cg, CURLOPT_);
//curl_setopt($cg, CURLOPT_RETURNTRANSFER, true);
$curlResult = curl_exec($cg);
There only other thing that I can think of that might be relevant at this point is that I'm processing all this over an unsecured connection on my end (no SSL cert yet). Any help is appreciated.
Thanks,
Brent