Laravel Socialite - Facebook extend/replace token with a one with more permissions -
i'm using laravel 5.4
, socialite
allow visitor of site log in.
situation
i obtained user_events
permission cause wanted add functionalities website.
before this, users got registered in database along user token in database. (token includes default permissions not user_events
)
i updated socialauthcontroller.php
reflect new permission on new created user , working great
return socialite::driver('facebook') ->scopes(['public_profile', 'user_events']) ->redirect();
problem
if user registered in database token, impossible run command $fb->get('me/events')
since token not include user_events
permissions.
questions
is there way force user grab new token new permission without having remove him database ? ( have data associated users) ?
socialauthcontroller
public function handleprovidercallback(socialaccountservice $service) { $user = $service->createorgetuser(socialite::driver('facebook')->user()); }
socialeaccountservice
public function createorgetuser(provideruser $provideruser) { $account = socialaccount::whereprovider('facebook') ->whereprovideruserid($provideruser->getid()) ->first(); if ($account) { return $account->user; } else { $account = new socialaccount([ 'provider_user_id' => $provideruser->getid(), 'provider' => 'facebook', 'nickname' => $provideruser->getnickname(), 'avatar' => $provideruser->avatar_original, 'token' => $provideruser->token, ]); $user = user::whereemail($provideruser->getemail())->first(); if (!$user) { $user = user::create([ 'email' => $provideruser->getemail(), 'name' => $provideruser->getname(), ]); } $account->user()->associate($user); $account->save(); return $user; }
Comments
Post a Comment