我试图使我的回调 url 动态化,因为我在多身份验证系统中配置社交名流。我尝试使用 socialiteproviders/manager
如下:
$clientId = env($provider."_client_id");
$clientSecret = env($provider."_client_secret");
$redirectUrl = "the url i want";
$config = new \SocialiteProviders\Manager\Config($clientId,$clientSecret,$redirectUrl);
return Socialite::with($provider)->setConfig($config)->redirect();
但它说:
Call to undefined method Laravel\Socialite\Two\FacebookProvider::setConfig()
尝试使用 facebook 登录时。
有人可以帮帮我吗?谢谢你。
最佳答案
我可以重现并找到解决方案。您提供的代码已过时,我在这里找到了其他实例:https://laravel.io/forum/07-28-2016-dynamic-callback-url-laravel-socialite
默认情况下,Socialite 将在 services.php
中获取提供者配置。通过传递 $providerName = facebook
所以你的代码现在变成:
// The services.php config will return null, fix it by using: strtoupper()
$clientId = env(strtoupper($provider . "_client_id"));
$clientSecret = env(strtoupper($provider . "_client_secret"));
$redirectUrl = "/the-url-i-want";
// ->redirect() acts as a closure, without it, you'll get an error like:
// "Serialization of 'Closure' is not allowed"
$user = Socialite::with($provider)->redirect();
return redirect()->to($redirectUrl)->with(['user', $user]);
有关使用 session 数据重定向的更多信息:
https://laravel.com/docs/6.x/redirects#redirecting-with-flashed-session-data
关于laravel - 动态回调 url laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38642439/