Back

Login with google using socialite issue.


This is my controller.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Socialite;
use Exception;
use Auth;
use URL;
use DB;

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

    public function callbackgoogle(Request $request) {
        try {
            // $gguser = Socialite::driver('google')->user();
            $gguser = Socialite::driver('google')->stateless()->user();
            echo '<pre>'; print_r($gguser); echo '</pre>'; exit();
        } catch (Exception $e) {
            return redirect('/course')->with('error','Something wrong please try after sometime!');
        }
    }
}

And below is error when callback from google.

Client error: `POST https://accounts.google.com/o/oauth2/token` resulted in a `400 Bad Request` response: { "error": "invalid_request", "error_description": "Missing required parameter: code" }

Please help me. Thank you in advance.

Jaydip Patel replied 2 weeks ago Solution

After a long search, the solution is to remove the 'profile' from scopes in vendor\laravel\socialite\src\Two\GoogleProvider.php

protected $scopes = [
    'openid',
    'email',
];

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us