Unable to use Laravel / Socialite with Lumen(无法在 Lumen 中使用 Laravel/Socialite)
问题描述
我尝试在我的系统
giga.com:8000 是我的本地主机(所以它是同一个本地主机:8000)
正如您在有效 OAuth 重定向 URI 中看到的那样,您应该将回调放在那里.就我而言,我使用三个网址,因为我有三种语言.在你的情况下它应该只是
http://your-domain-name.com:8000/callback如果你在 localhost 上工作,你应该在 config/services.php 中命名你的域我的看起来像这样
'domain' =>"your-domain.com",一切运行后,运行这些命令
php artisan cache:clearphp工匠视图:清除作曲家转储自动加载重新启动您的服务器,清除浏览器 cookie.希望有帮助
I try to use the package LaravelSocialite in my system in Lumen (5.1)
I added this in the configservices.php file :
<?php
//Socialite
'facebook' => [
    'client_id'     => '##################',
    'client_secret' => '##################',
    'redirect'      => 'http://local.dev/admin/facebook/callback',
],
In bootstrapapp.php file :
class_alias(LaravelSocialiteFacadesSocialite::class, 'Socialite');
$app->register(LaravelSocialiteSocialiteServiceProvider::class);
Then I created a controller for the facebook authentication :
<?php
namespace AppHttpControllersFacebook;
use AppHttpControllersController;
use LaravelSocialiteContractsFactory as Socialite;
class FacebookController extends Controller
{
  public function redirectToProviderAdmin()
  {
    return Socialite::driver('facebook')->scopes(['manage_pages', 'publish_actions'])->redirect();
  }
  public function handleProviderCallbackAdmin()
  {
    $user = Socialite::driver('facebook')->user();
  }
}
And in the routes.php :
$app->get('/admin/facebook/login', 'AppHttpControllersFacebookFacebookController@redirectToProviderAdmin');
$app->get('/admin/facebook/callback', 'AppHttpControllersFacebookFacebookController@handleProviderCallbackAdmin');
I just followed the documentation, changing according to my needs. When I go to page http://local.dev/admin/facebook/login, I get the following error :
Non-static method LaravelSocialiteContractsFactory::driver() cannot be called statically, assuming $this from incompatible context
Indeed, according to the code, driver function must be instanciate.
EDIT : And if I try to instanciate this class, I get the following error :
Cannot instantiate interface LaravelSocialiteContractsFactory
How do you make this module to work?
here's how that works in my case
in services.php file
 'facebook' => [
    'client_id' => '***************',
    'client_secret' => '***************',
    'redirect' => ""
],
i left redirect empty cause my site is multilingual (so, it fills in a bit later with sessions). if you use only one language, put there your callback absolute path. for example
"http://example.com:8000/my-callback/";
also check your config/app.php. in providers array
LaravelSocialiteSocialiteServiceProvider::class,
in aliases array
'Socialite' => LaravelSocialiteFacadesSocialite::class,
my routes look like this
Route::get('facebook', 'AuthAuthController@redirectToProvider');
Route::get('callback', 'AuthAuthController@handleProviderCallback');
here's auth controllers methods. put in top
use Socialite;
 //იობანი როტ
 public function redirectToProvider(Request $request)
{
    return Socialite::with('facebook')->redirect();
}
 public function handleProviderCallback(Request $request)
  {
    //here you hadle input user data
    $user = Socialite::with('facebook')->user();
  }
my facebook app
giga.com:8000 is my localhost (so its the same localhost:8000)
as you can see in Valid OAuth redirect URI, you should put there your callback. in my case i use three urls cause i have three languages. in your case it should be just
http://your-domain-name.com:8000/callback
if you work on localhost, you should name your domain in config/services.php mine look like this
'domain' => "your-domain.com",
after everything run these commands
php artisan cache:clear
php artisan view:clear
composer dump-autoload
restart your server, clear your browser cookies. hope it helps
这篇关于无法在 Lumen 中使用 Laravel/Socialite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在 Lumen 中使用 Laravel/Socialite
				
        
 
            
        基础教程推荐
- php中的foreach复选框POST 2021-01-01
 - php中的PDF导出 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				