问题描述
我是Laravel的新手,我正在关注,将用户通过Facebook登录到我的应用程序。然而,几乎无处不在,我发现一个教程使用Github或Twitter为Laravel提供的Socialite插件。
I am new to Laravel however and I am following the tutorial on http://www.codeanchor.net/blog/complete-laravel-socialite-tutorial/, to login a user through Facebook into my application. However, almost everywhere I find a tutorial using either Github or Twitter for the Socialite Plugin provided in Laravel.
我的问题是,在教程中遵循所有内容,因为我点击在登录到Facebook按钮时,它会引发无效的参数异常,并指定没有Socialite驱动程序。。
My problem is that on following everything in the tutorial, as I click on the "Login to Facebook" button, it throws an "Invalid Argument Exception" with No Socialite driver was specified.".
另一个堆栈溢出问题似乎将事情缩小:
Another stack overflow question seemed to narrow things down:https://stackoverflow.com/questions/29673898/laravel-socialite-invalidargumentexception-in-socialitemanager-php-line-138-n
说明问题出在配置/服务中。 php
Stating that the problem is in the config/services.php
现在,我有app_id和app_secret,但是,重定向链接似乎令人困惑,因为我在Facebook上找不到,我知道这个是我的应用程序应该去Facebook登录,但是,不确定它应该是什么
Now, i have the app_id and app_secret. However, the redirect link seems to be confusing as I can't find it on Facebook either. I am aware that this is where my app should go to Facebook for login, however, unsure of what it should be.
有没有人对此有任何想法。
Does anyone have any idea on this.
推荐答案
在你的composer.json add- laravel / socialite:〜2.0,
In your composer.json add- "laravel/socialite": "~2.0",
"require": {
"laravel/framework": "5.0.*",
"laravel/socialite": "~2.0",
运行作曲家更新
在 config / services.php 中添加:
//Socialite
'facebook' => [
'client_id' => '1234567890444',
'client_secret' => '1aa2af333336fffvvvffffvff',
'redirect' => 'http://laravel.dev/login/callback/facebook',
],
你需要创建两条路线,我的是这样的:
You need to create two routes, mine are like these:
//Social Login
Route::get('/login/{provider?}',[
'uses' => 'AuthController@getSocialAuth',
'as' => 'auth.getSocialAuth'
]);
Route::get('/login/callback/{provider?}',[
'uses' => 'AuthController@getSocialAuthCallback',
'as' => 'auth.getSocialAuthCallback'
]);
您还需要为上述路线创建控制器,如下所示:
You also need to create controller for the routes above like so:
<?php namespace App\Http\Controllers;
use Laravel\Socialite\Contracts\Factory as Socialite;
class AuthController extends Controller
{
public function __construct(Socialite $socialite){
$this->socialite = $socialite;
}
public function getSocialAuth($provider=null)
{
if(!config("services.$provider")) abort('404'); //just to handle providers that doesn't exist
return $this->socialite->with($provider)->redirect();
}
public function getSocialAuthCallback($provider=null)
{
if($user = $this->socialite->with($provider)->user()){
dd($user);
}else{
return 'something went wrong';
}
}
}
最后添加站点URL到您的Facebook应用程序像这样:
and finally add Site URL to your Facebook App like so:
这篇关于使用Laravel Socialite登录Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!