【问题标题】:Authenticating with Google OAuth使用 Google OAuth 进行身份验证
【发布时间】:2011-10-20 03:25:28
【问题描述】:

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

我正在使用 Codeigniter 2.0.2,我的服务器上没有编译 PECL OAuth,所以我必须使用原始 php 来执行此操作。

我已经通过 Google 对用户进行身份验证,并取回了该用户的 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
    }
}

我目前正在使用这个身份验证类的稍微修改过的版本:

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

【问题讨论】:

  • 还有这个问题吗?

标签: php oauth protected-resource


【解决方案1】:

您是否尝试过 Google OAuth Playground ?它有助于确定您可以访问哪些 API 供稿并构建有效的请求字符串。

以下是您可以访问的 Google API 列表:Google API Directory

希望有帮助

【讨论】:

    猜你喜欢
    • 2012-11-27
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2014-11-23
    相关资源
    最近更新 更多