Laravel 8: Google Authorization Error 400

I’m using Laravel 8 to develop my project and I would like to use Google authentication system for my users to login.

So I downloaded package via composer require laravel/socialite command and added my information on .env:

GOOGLE_CLIENT_ID=example
GOOGLE_SECRET_KEY=example
GOOGLE_CALLBACK_URL=http://localhost:8000/auth/google/callback

And then I defined them on config/services.php:

'google' => [
        'client_id' => env('GOOGLE_CLIENT_ID'),
        'client_secret' => env('GOOGLE_SECRET_KEY'),
        'redirect' => 'GOOGLE_CALLBACK_URL',
],

After that I created a controller on my auth/ directory which is called GoogleAuthController and goes like this:

use LaravelSocialiteFacadesSocialite;

class GoogleAuthController extends Controller
{
    public function redirect()
    {
        return Socialite::driver('google')->redirect();
    }
}

And finally at my login blade:

<a href="{{ route('auth.google') }}" class="btn btn-danger">Login with Google</a>

But the problem with this is that it, whenever I test this, it says:

Error 400: invalid_request

Invalid parameter value for redirect_uri: Missing scheme: GOOGLE_CALLBACK_URL

So why am I receiving this error ? How to fix it ?

I really appreciate any idea or suggestion from you guys…

Thanks in advance.

Also if you want to take a look at my routes, here it is:

Route::get('/auth/google', [AppHttpControllersAuthGoogleAuthController::class, 'redirect'])->name('auth.google');

Source: Laravel

Leave a Reply