Im currently working on an OAuth authentication system for my site that allows the login of users via the Google API.
Im working with Codeigniter 2.0.2 and I do not have PECL OAuth compiled on my server, so im having to use raw php to do this.
I have go as far as authenticating the user with Google, and getting back the oauth_token and oauth_token_secret for that user.
But after endless reading of the protocol I still cannot find how that oauth_key and oauth_token_secret to gain access to the other API to collect the following information:
- Email Address
- Profile Picture
- Full Name
- Location
Here is the current code that im using to authenticate:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class OAuth extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('google_oauth',array(
'key' => '*REMOVED*',
'secret' => '*REMOVED*',
'algorithm' => 'HMAC-SHA1'
));
}
public function login()
{
//Get Request Token
$response = $this->google_oauth->get_request_token(
site_url("/oauth/collect"),
'http://www.google.com/m8/feeds/'
);
//Store temp
$this->session->set_flashdata('g.token.secret', $response['token_secret']);
//Redirect
redirect($response['redirect']);
}
public function collect()
{
$token_s = $this->session->flashdata('g.token.secret');
if(!$token_s)
{
$this->session->set_flashdata('error','Invalid auth session data, please rety your login');
redirect();
}
$oauth = $this->google_oauth->get_access_token(false, $token_s);
/*Check the data is valid*/
if(!isset($oauth['oauth_token']) || !isset($oauth['oauth_token_secret']))
{
$this->session->set_flashdata('error','Unable to authecticate securly with Google, please try again');
redirect();
}
$token = $oauth['oauth_token'];
$secret = $oauth['oauth_token_secret'];
//Will Store Here
}
}
And im currently using a slightly modified version of this authentication class:
Have you tried experimenting with Google OAuth Playground ? Its useful for working out what API Feeds you can access and building valid request strings.
Here's a list of Google APIs you can access: Google API Directory
Hope that helps