Reputation: 170
I'm currently working on a Laravel Web-App and trying to use socialite/linkedin
, I've tried a lot of things on the internet, playing around whether it should be stateless or not, if it should be linkedin
or linkedin-openid
, but the one extends the other so it doesn't make a difference. And I can't progress further because I'm only getting the error:
Client error: `POST https://www.linkedin.com/oauth/v2/accessToken` resulted in a `400 Bad Request` response: {"error":"invalid_request","error_description":"Unable to retrieve access token: appid/redirect uri/code verifier does n (truncated...)
My code will be below here, and don't tell me some simple things like changing to -openid
or so, it doesn't work. I also have the correct permissions set up in the LinkedIn developer panel, it's all like in the documentation.
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Laravel\Socialite\Facades\Socialite;
class SocialiteController extends Controller
{
public function redirect($provider): \Symfony\Component\HttpFoundation\RedirectResponse
{
if (! in_array($provider, $this->getAllowedProviders())) {
abort(400);
}
return Socialite::driver($provider)->redirect();
}
public function callback($provider): \Illuminate\Http\RedirectResponse
{
if (! in_array($provider, $this->getAllowedProviders())) {
abort(400);
}
$socialiteUser = Socialite::driver($provider)
->stateless()
->user();
$user = User::updateOrCreate(
[
'provider' => $provider,
'provider_id' => $socialiteUser->getId(),
],
[
'name' => $socialiteUser->getName(),
'email' => $socialiteUser->getEmail(),
'provider' => $provider,
'provider_id' => $socialiteUser->getId(),
]
);
auth()->login($user, true);
$user->email_verified_at = now();
$user->save();
return redirect()->intended('/');
}
/**
* @return string[]
*/
private function getAllowedProviders(): array
{
return ['google', 'linkedin'];
}
}
I expect the LinkedIn OAuth via laravel/socialite
to work flawlessly.
Upvotes: 1
Views: 46