user9259038
user9259038

Reputation:

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 Laravel\Socialite\Facades\Socialite;

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', [App\Http\Controllers\Auth\GoogleAuthController::class, 'redirect'])->name('auth.google');

Upvotes: 1

Views: 1620

Answers (1)

Maarten Veerman
Maarten Veerman

Reputation: 1621

Your config is wrong:

'redirect' => 'GOOGLE_CALLBACK_URL',

Should be

'redirect' => env('GOOGLE_CALLBACK_URL'),

And of course this redirect should point to Google, not your localhost.

Upvotes: 1

Related Questions