Laravel Socialite: Missing required parameter: redirect_uri
Asked Answered
S

1

7

I am using Laravel 5.3 with Socialite.

I am getting 400 Bad Request error with message:

Missing required parameter: redirect_uri

The URL it generates is:

https://accounts.google.com/o/oauth2/auth?scope=openid+profile+email&response_type=code&state=RYPmT1B93CaUdi44Z7iwfmRPx3hIy7an7yxAVY9l

Details below:

service.php

'google' => [
        'client_id' => '1234455-u3ifk8tr1qs41487fmevg2h2s1v6ubue.apps.googleusercontent.com',
        'client_secret' => 'DxSOS0p1xKNuPger3IS_E4-i',
        'redirect' => 'http://localhost:8000/google/callback',
    ],

Routes

Route::get('/{provider}/redirect', 'Auth\RegisterController@redirectToProvider');
Route::get('/{provider}/callback', 'Auth\RegisterController@handleProviderCallback');

Authorized URI settings in Google Console

http://localhost:8000/google/callback

Controller

public function handleProviderCallback($provider)
    {
        try {
            $social_user = Socialite::driver($provider)->user();

        } catch (Exception $e) {
            return redirect('/');
        }
}
Stilla answered 8/12, 2016 at 16:36 Comment(3)
Might want to hide your ID and Secret from public view...Syntax
@AndyHolmes Don't worry, already altered :)Stilla
Well, the error seems obvious. You need to add the redirect_uri parameter to the request. ?redirect_uri=/some/uri.Nonferrous
L
1

Just double check your service.php file, env file and api setting in google console

Example (no env in redirect):

'google' => [
        'client_id' => env('GOOGLE_CLIENT_ID'),
        'client_secret' => env('GOOGLE_CLIENT_SECRET'),
        'redirect' => 'http://localhost:8000/api/login/google/callback'
],
Languor answered 15/2, 2023 at 21:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.