7

I am using "laravel/socialite": "^3.0", to facebook login. But it shows an error

Type error: Argument 1 passed to Laravel\Socialite\SocialiteManager::formatRedirectUrl() must be of the type array, null given, called in /var/www/html/mas/vendor/laravel/socialite/src/SocialiteManager.php.

It happens when I am calling the below function in my login controller

public function socialLogin($social)
{
    return Socialite::driver($social)->redirect();
}
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Nithin John
  • 897
  • 3
  • 8
  • 21

9 Answers9

23

Hi you are missing to give credentials of social media put that in config/services.php

'facebook' => [
        'client_id' => env('FACEBOOK_CLIENT_ID'),
        'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
        'redirect' => env('CALLBACK_URL_FACEBOOK'),
    ],
    'google' => [
        'client_id' => env('GOOGLE_CLIENT_ID'),
        'client_secret' => env('GOOGLE_CLIENT_SECRET'),
        'redirect' => env('CALLBACK_URL_GOOGLE'),
    ],
    'twitter' => [
        'client_id' => env('TWITTER_CLIENT_ID'),
        'client_secret' => env('TWITTER_CLIENT_SECRET'),
        'redirect' => env('CALLBACK_URL_TWITTER'),
    ],
    'linkedin' => [
        'client_id' => env('LINKEDIN_CLIENT_ID'),
        'client_secret' => env('LINKEDIN_CLIENT_SECRET'),
        'redirect' => env('CALLBACK_URL_LINKEDIN'),
    ],
    'instagram' => [
        'client_id' => env('INSTAGRAM_CLIENT_ID'),
        'client_secret' => env('INSTAGRAM_CLIENT_SECRET'),
        'redirect' => env('CALLBACK_URL_INSTAGRAM'),
    ],
  • I have that in my config/services.php. But It cann't read from vendor/laravel/socialite/src/SocialiteManager.php . I can access all other arrays in services.php, except facebook credentials. I don't know Why. – Nithin John Nov 20 '17 at 09:56
  • thanks, man I have missed these credential on the live server in config/services.php files now every thing is fine – shafeeque ahmad Jan 04 '20 at 18:37
19

You must clear the configuration cache file, how? if you use php artisan you will see the command config:clear. Run it:

php artisan config:clear

and now if you access to the $config variable inside the Laravel\Socialite\SocialiteManager::createFacebookDriver() you will get the configuration element stored in config/services.facebook (Facebook, for example) that before was not 'visible' for Socialite.

In short: run php artisan config:clear

Siro_Diaz
  • 297
  • 1
  • 3
  • 8
3

This happened to me just recently, fixed it after reading the following post here on StackOverflow:

Why do I have to run "composer dump-autoload" command to make migration work in laravel

The solution is basically to run the following commands:

php artisan clear-compiled composer dump-autoload php artisan optimize

2

The problem is with the parameters passed to the function socialLogin($social). Try by manually setting the 'github' or 'facebook' string in the drvier function of Socialite.

Dont forget to mention 'github' , 'facebook, etc in the route in web.php

2

I had same problem.

I got this errot because of copy/paste while reading Laravel doc. In my case in loginController.php changed this:

// I copied this from Laravel doc
public function redirectToProvider()
{
    return Socialite::driver('github')->redirect();
}

//What I really needed
public function redirectToProvider()
{
    return Socialite::driver('google')->redirect();
}
Mz1907
  • 625
  • 4
  • 10
1

I was having the same issue even after had set up my config/services.php file and managed to solve it by clearing my cache. In your project directory run

php artisan optimize:clear
php artisan cache:clear
php artisan config:clear
php artisan config:cache

This ensures that your entire cache is cleared.

NOTE: changing core files in Laravel most of the times require you running the above commands as Laravel tends to use caching to a greater extend to improve on application speeds

0

Try these

  1. Check if you have all your social media in config/services.php
  2. On your register or login page check the url that corresponds to facebook

    a href="{{ url('/login/facebook') }}"

  3. Go to Routes and check if you have routes properly configured

    Route::get('login/{social}', 'Auth\LoginController@redirectToProvider'); Route::get('login/{social}/callback', 'Auth\LoginController@handleProviderCallback');

  4. Open Auth/LoginController and check if have

    use Socialite; public function redirectToProvider($social) { Socialite::driver($social)->redirect(); } public function handleProviderCallback($social) { $user = Socialite::driver($social)->user(); }

As you've mentioned you are only facing the error with facebook, im pretty sure it must be in first three steps

0

Open vendor\laravel\socialite\src\SocialiteManager.php Replace to protected function formatRedirectUrl(array $config) { $redirect = value($config['redirect']);

    return Str::startsWith($redirect, '/')
                ? $this->app['url']->to($redirect)
                : $redirect;
}
0
Open vendor\laravel\socialite\src\SocialiteManager.php and 
Replace
  protected function createFacebookDriver()
    {
         $config = $this->app['config']['services.facebook'];
          return $this->buildProvider(
            FacebookProvider::class, $config
        );
    }

To
  protected function createFacebookDriver()
    {
         $config = $this->app['config']['services.stripe.facebook'];
          return $this->buildProvider(
            FacebookProvider::class, $config
        );
    }