2011-08-04 293 views
3

我目前正在为我的网站开发OAuth身份验证系统,该系统允许用户通过Google API登录。使用Google OAuth进行身份验证

我与Codeigniter 2.0.2一起工作,我没有在我的服务器上编译PECL OAuth,所以即时通讯必须使用原始的PHP来做到这一点。

我必须去尽可能认证与谷歌的用户,并取回了的oauth_tokenoauth_token_secret该用户。

但该协议的无尽的阅读后,我仍然无法找到怎么说oauth_keyoauth_token_secret来访问其他API来收集以下信息:

  • 电子邮件地址
  • 头像
  • 全名
  • 位置

下面是当前的代码,即时通讯使用验证:

<?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 
    } 
} 

和IM目前正在使用此认证类的略微修改的版本:

https://github.com/jimdoescode/CodeIgniter-YouTube-API-Library/blob/master/application/libraries/google_oauth.php

+0

仍然有这样的烦恼? – dmp

回答

相关问题