Asked  7 Months ago    Answers:  5   Viewed   28 times

I am new to Laravel however and I am following the tutorial on http://www.codeanchor.net/blog/complete-laravel-socialite-tutorial/, to login a user through Facebook into my application. However, almost everywhere I find a tutorial using either Github or Twitter for the Socialite Plugin provided in Laravel.

My problem is that on following everything in the tutorial, as I click on the "Login to Facebook" button, it throws an "Invalid Argument Exception" with No Socialite driver was specified.".

Another stack overflow question seemed to narrow things down: https://stackoverflow.com/questions/29673898/laravel-socialite-invalidargumentexception-in-socialitemanager-php-line-138-n

Stating that the problem is in the config/services.php

Now, i have the app_id and app_secret. However, the redirect link seems to be confusing as I can't find it on Facebook either. I am aware that this is where my app should go to Facebook for login, however, unsure of what it should be.

Does anyone have any idea on this.

 Answers

79

In your composer.json add- "laravel/socialite": "~2.0",

"require": {
        "laravel/framework": "5.0.*",
        "laravel/socialite": "~2.0",

the run composer update

In config/services.php add:

//Socialite
    'facebook' => [
        'client_id'     => '1234567890444',
        'client_secret' => '1aa2af333336fffvvvffffvff',
        'redirect'      => 'http://laravel.dev/login/callback/facebook',
    ],

You need to create two routes, mine are like these:

//Social Login
Route::get('/login/{provider?}',[
    'uses' => 'AuthController@getSocialAuth',
    'as'   => 'auth.getSocialAuth'
]);


Route::get('/login/callback/{provider?}',[
    'uses' => 'AuthController@getSocialAuthCallback',
    'as'   => 'auth.getSocialAuthCallback'
]);

You also need to create controller for the routes above like so:

<?php namespace AppHttpControllers;

 use LaravelSocialiteContractsFactory as Socialite;

 class AuthController extends Controller
 {

       public function __construct(Socialite $socialite){
           $this->socialite = $socialite;
       }


       public function getSocialAuth($provider=null)
       {
           if(!config("services.$provider")) abort('404'); //just to handle providers that doesn't exist

           return $this->socialite->with($provider)->redirect();
       }


       public function getSocialAuthCallback($provider=null)
       {
          if($user = $this->socialite->with($provider)->user()){
             dd($user);
          }else{
             return 'something went wrong';
          }
       }

 }

and finally add Site URL to your Facebook App like so:

enter image description here

Wednesday, March 31, 2021
 
fillobotto
answered 7 Months ago
62

After a long search, the solution is to remove the profile from scopes in vendorlaravelsocialitesrcTwoGoogleProvider.php

protected $scopes = [
    'openid',
    'email',
];
Friday, May 28, 2021
 
Sufi
answered 5 Months ago
51

You can try this:
1. In your FbApp disable the "require appsecret_proof for server API calls"
2. In your code, after line FacebookSession::setDefaultApplication($app_key,$app_secret);
add this line: FacebookSession::enableAppSecretProof(false);

Saturday, May 29, 2021
 
sholsinger
answered 5 Months ago
51

Looks like there is only one nice way to achieve this:

Although /me/groups requires user_groups permission to retrieve groups the user is a member of, it can return groups created by the app without it (given there is a valid access token of course).

So - while it's clearly not as nice and seamless as I wanted it to be - my solution was to create a new Facebook group using the app (requires only a POST request) and move current members to this new one.

Edit: moving members is not a possibility, joining an app group is only possible programatically using the SDK. Therefore, when a user is not a member of this group, I'll prompt them to join. It means that everybody can join and I have to manually ban those I don't like instead of manually allowing those I want to, but given the low publicity, I can deal with this.

Saturday, May 29, 2021
 
KHM
answered 5 Months ago
KHM
52

Just found my answer. Need to use stateless in both calls:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()

$fb_user = Socialite::with('facebook')->stateless()->user();

Hope this helps someone.

Thursday, September 9, 2021
 
Averroes
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share