问题描述
我想在我的cakePHP应用程式中使用Google OAuth,让使用者使用自己的Google帐户登入。我查看了以下组件:。不知怎的,我不能得到它和工作。我不知道我做错了什么。我在Google注册表单上注册了我的申请,并获得了我的Consumer Key和Consumer Secret。我在消费者组件中添加了它。
I would like to use Google OAuth in my cakePHP application to let the users login with their google account. I looked at the following component: http://code.42dh.com/oauth/ . Somehow I am not able to get it up and working. I don't know what I am doing wrong. I registered my application on the Google registration form and got my Consumer key and Consumer secret. I added it in the consumer component. I still don't get it to work.
这是我的代码:
<?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时,我得到答案:签名无效。
When I try to request the requestToken I get the answes: "signature invalid".
有人在他们的cakePHP应用程序中使用Google OAuth,并愿意给我一些提示吗?
Did someone use Google OAuth within their cakePHP application and would be willing to give me some tips?
推荐答案
我认为问题是请求令牌url中的querystring。尝试以下操作:
I think the issue is the querystring in the request token url. Try the following:
$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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!