Laravel 5.5 socialite integration shows error formatRedirectUrl() must be of the type array, null given

a 夏天 提交于 2020-03-01 04:17:47

问题


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();
}

回答1:


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'),
    ],



回答2:


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




回答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




回答4:


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




回答5:


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();
}



回答6:


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




回答7:


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;
}



回答8:


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
        );
    }


来源:https://stackoverflow.com/questions/47365532/laravel-5-5-socialite-integration-shows-error-formatredirecturl-must-be-of-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!