laravel4 hybridauth facebook Authentication failed

2019-01-25 19:07发布

OK, I'm trying to use Hybridauth with laravel 4. However I seem to be getting the very common when trying to log in with facebook:

Authentication failed! Facebook returned an invalid user id.

I have read all the other posts, and have had no luck, so just hoping someone may be able to help me.

I followed this tutorial: http://www.mrcasual.com/on/coding/laravel4-package-management-with-composer/

And have tried several other configurations to no success.

Here is my config/hybridauth.php

<?php
return array(
    "base_url"   => "http://myapp.dev/social/auth/",
    "providers"  => array (
        "Facebook"   => array (
            "enabled"    => true,
            "keys"       => array ( "id" => "****", "secret" => "****" ),

        ),
    ),
);

And here is my route:

Route::get('social/{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 Facebook
        $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();
}));

So, when I access "myapp.dev/social" I'm brought to the facebook sign up page everthing seems to work fine, asks me to allow permissions to myadd.dev. After I click OK I am brought to the following URL: http://myapp.ie/social#_=_ where the error is displayed.

Not sure if this is relevant: Just from observing other sites that in-cooperate a facebook login.. the redirect URL looks something like http://somesite.dev/subdomain/#_=_ . In other words they have a slash before the #=. Is this my problem, how do I fix it?? Very new to hybridauth so any help greatly appreciated thanks.

Oh I do realize that this post is very similar to other posts but I have yet to find a solution.

UPDATE: the exact error: Authentification failed. The user has canceled the authentication or the provider refused the connection.

10条回答
劳资没心,怎么记你
2楼-- · 2019-01-25 19:09

REMOVE THE TRAILING SLASH !!! (in config/hybridauth.php)

"base_url" => "http://myapp.dev/social/auth/",

should be

"base_url" => "http://myapp.dev/social/auth",

查看更多
beautiful°
3楼-- · 2019-01-25 19:10

I had the exact same error message on a wordpress installation using Hybridauth. To find the problem I set up an isolated test with the Facebook PHP SDK (which Hybridauth uses) just to find out that curl_exec was not enabled on my host. Happily, an easy fix.

If you are on apache open you php.ini and delete curl_exec from this line:

disable_functions = curl_exec

Reload your apache configuration and voila :)

Hope this will help somebody.

查看更多
男人必须洒脱
4楼-- · 2019-01-25 19:11

Had this error in the past. Solved by modyfying Hybridauth's code myself.

  1. In thirdparty/Facebook/base_facebook.php make sure $CURL_OPTS array uses: CURLOPT_SSL_VERIFYPEER => false
  2. In my case I was closing session files for performance improvements so I added: session_start() inside Storage.php wherever HA::STORE session var is being updated/unset.

Let me know if it helps.

查看更多
祖国的老花朵
5楼-- · 2019-01-25 19:12

In base_facebook.php do following

  public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 50,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.2',
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
  );

  protected $trustForwarded = true;
  protected $allowSignedRequest = false;
查看更多
爷的心禁止访问
6楼-- · 2019-01-25 19:15

For anyone else this is what worked for me: I reset app secret and now works great. No idea why my first app secret key did not work. Spent a ridiculous amount of time trying to fix this error.

查看更多
三岁会撩人
7楼-- · 2019-01-25 19:17

CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false

at modules/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php:128

solved!

查看更多
登录 后发表回答