check first your redirect url is correct and run command:
php artisan passport:install
see this below snippet may help you
public function socialRedirect($provider)
{
if ($provider === 'clever') {
$clientId = Config::get('services.clever.client_id');
$redirect = Config::get('services.clever.redirect');
return redirect()->away('https://clever.com/oauth/authorize?response_type=code&redirect_uri=' . $redirect . '&client_id=' . $clientId);
} else {
return Socialite::driver($provider)->redirect();
}
}
public function socialCallback($provider)
{
if ($provider === 'apple') {
$token = app(Configuration::class)->parser()->parse(app(AppleToken::class)->generate());
config()->set('services.apple.client_secret', $token);
}
$socialUser = Socialite::driver($provider)->setHttpClient(new Client(['verify' => false]))->user();
$userIdentity = UserIdentity::where('provider_id', $socialUser->id)->where('provider_name', $provider)->first();
$userRole = UserRole::where('slug', 'user')->first();
if ($userIdentity) {
// retrieve the user from users store
$user = User::where('id', $userIdentity->user_id)->with('userRole')->with('account')->first();
// assign access token to user
$token = $user->createToken('social');
$accessToken = $token->accessToken;
$arguments = [
'success' => true,
'accessToken' => $accessToken,
'expiresAt' => Carbon::parse($token->token->expires_at)->toDateTimeString(),
'user' => json_encode($user)
];
return redirect()->away(env('CLIENT_URL') . '/social/callback?' . http_build_query($arguments));
} else {
$user = User::where('email', $socialUser->email)->with('userRole')->with('account')->first();
if (!($user && isset($user->id))) {
/* $newUser = User::create([
'fname' => $socialUser->name ?? '',
'lname' => '',
'email' => $socialUser->email,
'image' => $socialUser->avatar ?? '',
'user_role_id' => $userRole->id,
'account_id' => 1,
'password' => Hash::make(Str::random(40)),
'status' => 'active',
]);
$user = User::where('email', $socialUser->email)->with('userRole')->with('account')->first(); */
$arguments = [
'success' => false,
];
return redirect()->away(env('CLIENT_URL') . '/social/callback?' . http_build_query($arguments));
} else {
// store user social provider info
if ($user) {
UserIdentity::create([
'provider_name' => $provider,
'provider_id' => $socialUser->id,
'user_id' => $user->id,
]);
}
// assign passport token to user
$token = $user->createToken('social');
$accessToken = $token->accessToken;
$arguments = [
'success' => true,
'accessToken' => $accessToken,
'expiresAt' => Carbon::parse($token->token->expires_at)->toDateTimeString(),
'user' => json_encode($user)
];
return redirect()->away(env('CLIENT_URL') . '/social/callback?' . http_build_query($arguments));
}
}
POST https://www.googleapis.com/oauth2/v4/token
resulted in a400 Bad Request
response:↵{↵ "error": "invalid_request",↵ "error_description": "Missing required parameter: code"↵}↵ – Unevenphp artisan serve
? – Mani