私は現在、Google API を介してユーザーのログインを許可する私のサイトの OAuth 認証システムに取り組んでいます。
Codeigniter 2.0.2 を使用していますが、サーバーで PECL OAuth をコンパイルしていないため、生の php を使用してこれを行う必要があります。
Google でユーザーを認証し、そのユーザーのoauth_tokenとoauth_token_secretを取得しました。
しかし、プロトコルを無限に読んだ後でも、そのoauth_keyとoauth_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
}
}
そして、現在、この認証クラスのわずかに変更されたバージョンを使用しています: