Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Socialite: How to change redirect_uri at runtime?

Is is possible to change the value of redirect_uri set in config/services.php at runtime?

I tried doing like this:

return $socialite->driver('facebook')->redirectUrl(newUrl)->redirect();

but it throws an error saying that the redirect_uri should match the one from the OAuth dialog. Upon further checking of the error message, the value of redirect_uri is empty so apparently, the redirectUrl() method does not work.

PS:

This is the socialite version that I'm using defined in composer.json:

"laravel/socialite": "^2.0"

like image 433
Jay Avatar asked Oct 17 '22 11:10

Jay


1 Answers

The solution to this is:

public function redirectToProvider($accountType, $provider)
{
    return Socialite::driver($provider)
        ->with(['redirect_uri' => "YOUR_NEW_URL"])
        ->stateless()
        ->redirect();
}

With this method, you could override any of the values in the http request (including the scope).

like image 182
Tochukwu Nkemdilim Avatar answered Oct 21 '22 05:10

Tochukwu Nkemdilim