10

I have this strange issue with using Laravel Socialite to log users in via Google API.

Everything configurations seem normal and ordinary, but I keep getting error Missing required parameter: client_id. Not only that, sometimes I tried again and the error became Missing required parameter: redirect_uri despite all these parameters have been supplied.

This is how it is set up:

service.php

'google' => [
        'client_id' => 'xxxxxxxxxx-x98asxxxx913ofk5tqvgq7lqfpgdi5u2.apps.googleusercontent.com',
        'client_secret' => 'mklOWJFhpbCzTKxxxx-xxxx',
        'redirect' => 'http://myapp.com/auth/google/callback'
    ],

routes.php

Route::get('/auth/{social_channel}', 'Auth\AuthController@redirect_to_provider');

Route::get('/auth/{social_channel}/callback', 'Auth\AuthController@handle_provider_callback');

AuthController.php

/**
     * Redirect the user to the Google authentication page.
     *
     * @return Response
     */
    public function redirect_to_provider($social_channel)
    {
        return Socialite::driver($social_channel)->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return Response
     */
    public function handle_provider_callback($social_channel, SocialAccountService $service)
    {
        $user = $service->create_or_get_user($social_channel, Socialite::driver($social_channel)->user());

        Auth::login($user);

        return redirect()->to('/go');

    }

Facebook Login works for me, just this Google Login issue is a stubborn and bizarre problem.

The app is deployed on Forge (Ubuntu, Nginx).

Can anybody spot anything wrong with this at all?

nogias
  • 563
  • 2
  • 6
  • 23

3 Answers3

7

With env() function in the services.php file, you must use GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in the .env file, without white spaces.

GOOGLE_CLIENT_ID=xxxxxxxxxxxx    
GOOGLE_CLIENT_SECRET=xxxxxxxxxxxxxx

in the services file, use this

'client_id' => env('GOOGLE_CLIENT_ID'),         
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
Armand
  • 2,611
  • 2
  • 24
  • 39
Felipe Castillo
  • 536
  • 8
  • 25
6

I just solved the same problem, my first solution is by passing the client_id and secret on the controller using the ->with(). Code goes like this:

    return Socialite::driver('google')
    ->with(
        ['client_id' => 'xxxxxxxx'],
        ['client_secret' => 'xxxxxxxx'],
        ['redirect' => 'http://localhost:8000/Yourcallback'])
    ->redirect();

OR just by removing the env() on services.php

    'client_id' => env('xxxxxxx'),
    'client_secret' => env('xxxxxxx'),

with this

'client_id' => 'xxxxxxx',
'client_secret' => 'xxxxxxx',

Its seems that Socialite does not recoginized env() function.

KirtJ
  • 550
  • 7
  • 7
  • I did it like you offer, but without client_secret. Isn't it security issue if you add client_secret? – Vit Apr 15 '20 at 11:42
0

For people out there that are using Forge, you may need to add the google .env information in the environment tab on your Forge panel. This .env information is not pushed through Github to Forge.

Gass
  • 7,536
  • 3
  • 37
  • 41