使用Laravel 4测试使用hybridauth在localhost服务器上登录Facebook

时间:2013-06-18 23:54:36

标签: facebook localhost laravel laravel-4 hybridauth

我正在尝试按照此处的教程设置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上:

App Domain:mactest.dynalias.com 网站网址:http://mactest.dynalias.com

这是我的代码:

hybridauth.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" )
            )
    ),
);

routes.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按钮时,似乎没有任何内容发生,并且网址只会更改为:

http://mactest.dynalias.com:8888/crowdsets/laravel-master/public/fans/landing?provider=Facebook

3 个答案:

答案 0 :(得分:3)

尝试删除hybridauth.php base_url上的尾部斜杠。适合我。答案由@MrCasual here

提供

答案 1 :(得分:1)

将您的base_url更改为:

URL::route('hybridauth', array('action' => 'auth'));

答案 2 :(得分:0)

[解决方案]删除尾部斜杠: