query('target_url', url('/')); Session::put('target_url', $targetUrl); return Socialite::driver('google')->redirect(); }); Route::get('/auth/callback', function () { $googleUser = Socialite::driver('google')->user(); $token = $googleUser->token; $targetUrl = Session::pull('target_url', url('/')); $separator = parse_url($targetUrl, PHP_URL_QUERY) ? '&' : '?'; $redirectUrl = $targetUrl . $separator . 'access_token=' . urlencode($token); return redirect()->to($redirectUrl); });