ここのチュートリアルに従って、Facebook ログインをセットアップしようとしています。
http://www.mrcasual.com/on/coding/laravel4-package-management-with-composer/#additional_resources
ローカル サーバーでサイトを実行しています (dyndns ホスト名を設定して、Facebook アプリがそれを指すようにします)。Facebookログインをしたいページは次のとおりです。
http://mactest.dynalias.com:8888/crowdsets/laravel-master/public/fans/landing
Facebookで:
アプリ ドメイン:mactest.dynalias.com サイト URL: http://mactest.dynalias.com
これが私のコードです:
ハイブリッド認証.php:
<?php
return array(
"base_url" => "http://mactest.dynalias.com:8888/crowdsets/laravel-master/public/fans/landing/auth/",
"providers" => array (
"Google" => array (
"enabled" => false,
"keys" => array ( "id" => "ID", "secret" => "SECRET" ),
),
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "***************", "secret" => "******************" ),
"scrop" => "first_name,last_name,email,user_birthday,gender,user_location,friends,
),
"Twitter" => array (
"enabled" => false,
"keys" => array ( "key" => "ID", "secret" => "SECRET" )
)
),
);
ルート.php:
Route::get('fans/landing', array('uses' => 'GuestController@getIndex'));
Route::get('fans/landing/{action?}', array("as" => "hybridauth", function($action = "")
{
// check URL segment
if ($action == "auth") {
// process authentication
try {
Hybrid_Endpoint::process();
}
catch (Exception $e) {
// redirect back to http://URL/social/
return Redirect::route('hybridauth');
}
return;
}
try {
// create a HybridAuth object
$socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
// authenticate with Google
$provider = $socialAuth->authenticate("facebook");
// fetch user profile
$userProfile = $provider->getUserProfile();
}
catch(Exception $e) {
// exception codes can be found on HybBridAuth's web site
return $e->getMessage();
}
// access user profile data
echo "Connected with: <b>{$provider->id}</b><br />";
echo "As: <b>{$userProfile->displayName}</b><br />";
echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";
// logout
$provider->logout();
}));
私からしてみれば:
<div id="facebook">
<span class="button-signin-facebook"><div class="facebook_connect_wrap small"><a href="?provider=Facebook">Sign up with Facebook</a></div></span>
</div>
Facebook ボタンをクリックしても、何も起こらないように見え、URL が次のように変わります。
http://mactest.dynalias.com:8888/crowdsets/laravel-master/public/fans/landing?provider=Facebook