Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

axtg's avatar
Level 5

Socialite delete connection

I was wondering if anyone else looked into how to use Socialite for disconnecting the link between a social provider and my Laravel site.

Two use cases:

  1. Upon account deletion at my site, I'd like to call a method that announces the disconnect request with FB;
  2. Upon disconnection at FB, I'd like to process FB's callback at my site.

If Socialite doesn't support this, then 2. I can figure out myself, but for 1 I'm unsure how to address it. So perhaps I can benefit from someone's hands-on experience here :-).

0 likes
3 replies
bobbybouwmann's avatar

You can't do that with the basic socialite library. However most API's offer an api which you can use. So you have to build this yourself!

For example Twitter:

https://developer.twitter.com/en/docs/basics/authentication/api-reference/invalidate_bearer_token

Users can also revoke at other sites, you can probably setup a webhook url for that which points to your application so you can then delete the token. At least, that's how it works in most cases.

2 likes
sadiq79's avatar
 public function user()
    {
        if ($this->hasInvalidState()) {
            throw new InvalidStateException;
        }
 
        $response = $this->getAccessTokenResponse($this->getCode());
 
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = Arr::get($response, 'access_token')
        ));
 
        return $user->setToken($token)
                    ->setRefreshToken(Arr::get($response, 'refresh_token'))
                    ->setExpiresIn(Arr::get($response, 'expires_in'));
    }
 public function callback()
    {
        $user = Socialite::driver('google')->user();
//        echo '<pre>';print_r($user); die;
//        return Socialite::driver('google')->stateless()->user();
       # return Socialite::driver('google')
       #     ->with(['hd' => 'example.com'])
          #  ->redirect();

Error: Laravel \ Socialite \ Two \ InvalidStateException No message

Please or to participate in this conversation.