CakePHP OAuth 与 Google

标签 cakephp oauth

我想在我的 cakePHP 应用程序中使用 Google OAuth,让用户使用他们的 google 帐户登录。我查看了以下组件:http://code.42dh.com/oauth/ .不知何故,我无法启动并工作。我不知道我做错了什么。我在谷歌注册表上注册了我的应用程序,并获得了我的消费者 key 和消费者 secret 。我在消费者组件中添加了它。我仍然没有让它工作。

这是我的代码:

<?php

class ExampleController extends AppController {
public $uses = array();
var $helpers = array('Javascript', 'Ajax');
public $components = array('OauthConsumer');

public function google() {

    $scope = "https://www.google.com/m8/feeds/";
    $REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken?scope=' . urlencode($scope);

    $requestToken = $this->OauthConsumer->getRequestToken('Google', $REQUEST_TOKEN_URL, 'http://mydomain.com/example/google_callback');
    $this->Session->write('google_request_token', $requestToken);
    $this->redirect('https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=' . $requestToken->key);
}

public function google_callback() {
    $requestToken = $this->Session->read('google_request_token'); 
    $accessToken = $this->OauthConsumer->getAccessToken('Google',   'https://www.google.com/accounts/OAuthGetAccessToken', $requestToken); 

 }
 }

 ?>

当我尝试请求 requestToken 时,我得到了答案:“签名无效”。

是否有人在其 cakePHP 应用程序中使用了 Google OAuth 并愿意给我一些提示?

最佳答案

我认为问题在于请求 token url 中的查询字符串。请尝试以下操作:

$REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken';
$requestToken = $this->OauthConsumer->getRequestToken('Google', $REQUEST_TOKEN_URL, 'http://mydomain.com/example/google_callback', 'GET', array('scope' => 'https://www.google.com/m8/feeds'));

关于CakePHP OAuth 与 Google,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741501/

相关文章:

Spring boot OAuth成功登录监听器未触发

php - 我想在 mysql 的 3 个表中使用左连接和内连接?

shell - Cakephp httpsocket ssl 不适用于控制台 shell

c# - 如何在 C# .NET 中实现 OAuth2 提供者和消费者

java - 如何使用 OAuth2 向 Mendeley 进行身份验证

security - 单页 Web 应用程序、CORS 和安全问题

CakePhp:使用重命名的模型字段进行动态关联?

javascript - 如何将 javascript var 传递到 ajax RemoteFunction 中?

php - CakePHP 容器和模型关联

python - django 1.7 makemigrations 需要我尝试删除的依赖项