Search code examples
laravel-8laravel-socialite

Socialite Laravel. How to get custom parameters?


I develop API endpoint for binding social network account to exists account in our system. As it is API I can't use sessions but I need identificate of user that know what user I need binding. In the Laravel documentation for Socialite functionality I see that I can use "with" method to send custom parameters but there not write how I can get these parameters in incoming request. How I can get these parameteres? I would be grateful for any help. Thanks.

Method for generate social link with uid parameter:

public function redirectToProvider($provider)
{
    return Socialite::driver($provider)
        ->with([
            'uid' => "Auth::id()"
        ])
        ->stateless()
        ->redirect()
        ->getTargetUrl();
}

Callback method from social network:

 public function handleProviderCallback($provider)
{
    $user = Socialite::driver($provider)
        ->stateless()
        ->user();

    return $user;

}

Solution

  • Correct solution ->with ('state' => Auth :: id ())