我想在我的 cakePHP 应用程序中使用 Google OAuth 让用户使用他们的 google 帐户登录。我查看了以下组件:http://code.42dh.com/oauth/ http://code.42dh.com/oauth/。不知怎的,我无法让它启动并工作。我不知道我做错了什么。我在 Google 注册表单上注册了我的应用程序并获得了我的消费者密钥和消费者秘密。我将其添加到消费者组件中。我仍然没有让它发挥作用。
这是我的代码:
<?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 并愿意给我一些提示吗?
我认为问题在于请求令牌 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'));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)