我目前正在为我的网站开发一个OAuth认证系统,允许用户通过Google API登录。
我使用Codeigniter 2.0.2,我没有PECL OAuth在我的服务器上编译,所以我不得不使用原始php来做这件事。
我已经用Google对用户进行了身份验证,并为该用户获取oauth_token和oauth_token_secret。
但是在无休止地阅读协议之后,我仍然无法找到oauth_key和oauth_token_secret如何访问其他API来收集以下信息:
- <
- 电子邮件地址/gh>
- 概要图
- 全名
下面是我用来验证的当前代码:
<?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
}
}
我现在使用这个认证类的一个稍微修改的版本:
https://github.com/jimdoescode/CodeIgniter-YouTube-API-Library/blob/master/application/libraries/google_oauth.php你尝试过Google OAuth Playground吗?这对于确定可以访问哪些API feed和构建有效的请求字符串很有用。
这里是一个你可以访问的Google API列表:
希望有帮助