2012-01-05 17 views
13

cakePHPアプリケーションでGoogle OAuthを使用して、ユーザーがGoogleアカウントでログインできるようにしたいと思います。私は次のコンポーネントを調べました:http://code.42dh.com/oauth/。どういうわけか私はそれを立ち上げて働くことができません。私は何が間違っているのか分かりません。 Google登録フォームに自分のアプリケーションを登録し、コンシューマーキーとコンシューマーシークレットを取得しました。私はそれを消費者コンポーネントに追加しました。私はまだそれを動作させることはありません。 "無効な署名":私はanswesを得るrequestTokenを要求しようとするとCakePHP OAuth with 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); 

} 
} 

?> 

は、ここに私のコードです。

誰かがcakePHPアプリケーションでGoogle OAuthを使用しましたか?私にいくつかのヒントをお寄せください。

答えて

6

私はこの問題がリクエストトークン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')); 
0

あなたは公開APIアクセスキーとcliendのIDと秘密鍵との接続が許可されたURLリファラーを忘れてしまった...

は、パブリックAPIへのアクセスを作成し、お使いの設定でそれを追加。