Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

naveen's avatar

Adding social login using hybrid auth laravel5

Hi I am new to laravel I am trying to add Social login to laravel 5 app. I was able to add it successfully to laravel 4.2.16 but when I am trying the similar setup in 5 its not working. Basically I have added a link to Login Page Login Using Facebook But when I click on it it tries to find route auth/facebookAuth and then fails

Method [missingMethod] does not exist. in compiled.php line 8023 at Controller->__call('missingMethod', array('facebookAuth')) at AuthController->missingMethod('facebookAuth') at call_user_func_array(array(object(AuthController), 'missingMethod'), array('_missing' => 'facebookAuth')) in compiled.php line 8019 at Controller->callAction('missingMethod', array('_missing' => 'facebookAuth')) in compiled.php line 8082 at ControllerDispatcher->call(object(AuthController), object(Route), 'missingMethod') in compiled.php line 8061

below is my routes.php

Route::get('/', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Route::get('facebookAuth/{auth?}', array("as" => "facebookAuth", 'uses'=>'AuthController@getFacebookLogin')); Route::get('googleAuth/{auth?}', array("as" => "googleAuth", 'uses'=>'AuthController@getGoogleLogin')); Route::get('logout', array("as" => "logout", 'uses'=>'AuthController@getLoggedOut'));

Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController',

]);

Please help.

0 likes
6 replies
christopher's avatar

Can you post your full AuthController Code ( or edit your current post with your AuthController for others ) ?

naveen's avatar

Thanks for looking at my question here is my Auth\AuthController.php

<?php namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller {

/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers; 

public function getFacebookLogin($auth=NULL)
{
    if($auth == 'auth')
    {       
        Hybrid_Endpoint::process();
        return;
    }
    try
    {
        $oauth = new Hybrid_Auth(app_path('/config/facebookAuth.php'));
        $provider = $oauth->authenticate('Facebook');
        $profile = $provider->getUserProfile();
    }
    catch(Exception $e)
    {
        return Redirect::to('facebookAuth');
    }
    return var_dump($profile).'<br><a href="logout">Logout</a>';
}   

public function getGoogleLogin($auth=NULL)
{
    if($auth == 'auth')
    {       
        try
        {
            Hybrid_Endpoint::process();
        }
        catch(Exception $e)
        {
            return Redirect::to('googleAuth');
        }
        return;
    }
    $oauth = new Hybrid_Auth(app_path('/config/googleAuth.php'));
    $provider = $oauth->authenticate("Google");
    $profile = $provider->getUserProfile();
    return var_dump($profile).'<br><a href="logout">Logout</a>';

}   

public function getLoggedOut()
{
        $auth = new Hybrid_Auth(app_path('/config/facebookAuth.php'));      
        $auth->logoutAllProviders();

        return View::make('login');
}

}

christopher's avatar

If you post a form or login you need to create a route::post not get because you post something to the controller ( login data ). Try something like this:

Route::post('facebookAuth/{auth?}', array("as" => "facebookAuth", 'uses'=>'AuthController@getFacebookLogin')); 
naveen's avatar

I am not posting a form. I have just added a a href link to login.blade.php to authenticate using facebook. But its not working. I tried POST too.. still no luck :(

Please or to participate in this conversation.