laravel 第三方登录

首先安装依赖

1.命令行到达laravel目录

2.安装第三方插件

QQ: Composer require socialiteproviders/qq

3.配置

a) 开启config/app.php配置
(1)

'providers' => [
    // 移除 'Laravel\Socialite\SocialiteServiceProvider',
    SocialiteProviders\Manager\ServiceProvider::class, // 添加
];

(2)在aliases中加入Socialite
'Socialite'=> Laravel\Socialite\Facades\Socialite::class,

(3)添加事件监听器(App/Providers/EventServiceProvider)

  protected $listen = [
    'SocialiteProviders\Manager\SocialiteWasCalled' => [
        'SocialiteProviders\QQ\QqExtendSocialite@handle',
    ],
];

b) 在config/services.php中添加:

'qq' => [
   'client_id' => env('QQ_KEY'),
   'client_secret' => env('QQ_SECRET'),
   'redirect' => env('QQ_REDIRECT_URI'),  
], 

c) 在.env中添加

QQ_KEY =101417436
QQ_SECRET =70c1a699472cc945480474ba37130336
QQ_REDIRECT_URL =http://myjob.app/login/qqlogin

Qq这三个参数在QQ互联申请:https://connect.qq.com/

d) 路由

Route::get('/qqlogin','LoginController@qqlogin');
Route::get('/qq','LoginController@qq');

e) 控制器

Use  Laravel\Socialite\Facades\Socialite;//要引用类
Public function qq(){
 Return Socialite::with('qq')->redirect();
}
Public function qqlogin(){
 $user =Socialier::driver('qq')->user():
 dd($user);
}

Weibo的方式和qq相似

你可能感兴趣的:(laravel 第三方登录)