2

I making OAuth using Laravel Socialite, step by step i trying 3 different guides and result the same error Trying to access array offset on value of type null.

My composer.json

"require": {
        "php": "^7.3.1",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^6.2",
        "laravel/socialite": "^4.3",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^1.2",
        "socialiteproviders/vkontakte": "^4.0"
    },

Also my LoginController

public function redirectToProvider()
    {
        return Socialite::driver('github')->redirect();
    }

    public function handleProviderCallback()
    {
        $user = Socialite::driver('github')->user();

        dd($user);
    }
Malzeriy
  • 127
  • 2
  • 13

3 Answers3

13

if you entered your client_id and secret_id config/services.php then run php artisan config:clear

Arman
  • 481
  • 4
  • 12
mehmetakkus
  • 631
  • 1
  • 8
  • 25
3

probably you forgot to add services to you services.php so go to config/services and add

'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect' => env('GITHUB_REDIRECT'),
    ],
 'google' => [
        'client_id' => env('GOOGLE_CLIENT_ID'),
        'client_secret' => env('GOOGLE_CLIENT_SECRET'),
        'redirect' => env('GOOGLE_REDIRECT'),
    ]

after that go to env and add to your providers keys and values

Ayoub ait
  • 163
  • 2
  • 4
-2

I had faced the same issue and I finally came to a solution. The problem is probably due to the depreciation of app['request'] in SocialiteManager.php file located in Vendor/Laravel/Socialite/src/SocialiteManager.php.

The solution to this problem is by following the following steps:

Step 1: Go to Vendor/Laravel/Socialite/src/SocialiteManager.php.
Step 2: Copy and paste the following code in buildProvider method.

public function buildProvider($provider, $config)
    {
        return new $provider(
            $this->container->make('request'),
            $config['client_id'],
            $config['client_secret'],
            $this->formatRedirectUrl($config),
            Arr::get($config, 'guzzle', [])
        );
    }

Step 3: Run php artisan config:cache and php artisan cache:clear to clear the previous cache then run the app. Hola! You're done!

Undo
  • 25,519
  • 37
  • 106
  • 129