Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Socialite - google login failed "Missing required parameter: client_id" although specified

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?

like image 751
nogias Avatar asked May 15 '16 13:05

nogias


People also ask

How to configure Google social login with Laravel?

In this step, configure Google app with this laravel app. So, open your laravel Google social login project in any text editor. Then navigate the config directory and open service.php file and add the client id, secret and callback url:

How to install socialite on Laravel 6?

Step 1: Install Laravel 6 In this step, if you haven't laravel 6 application setup then we have to get fresh laravel 6 application. So run bellow command and get clean fresh laravel 6 application. Step 2: Install Socialite

How to clone my Laravel 9 login code?

To shorten this tutorial we need to clone my code about Laravel 9 login just copy the repo link below: Once done copy the folder inside your htdocs folder if you are using Xampp. And rename the folder of what you want. After the folder is already inside the htdocs.

Why am I getting a client_ID error message?

The error message indicate that you haven't filled in the box for client_id. If what you reproduce from the request details in the issue summary is all of it, it also looks like you're sending much less data than what is expected. Log inor registerto post comments Comment #5


2 Answers

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'),
like image 57
Felipe Castillo Avatar answered Oct 19 '22 20:10

Felipe Castillo


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.

like image 38
KirtJ Avatar answered Oct 19 '22 21:10

KirtJ