Laravel5.4框架使用socialite实现github登录的方法
本文实例讲述了Laravel5.4框架使用socialite实现github登录的方法。分享给大家供大家参考,具体如下:
1.安装laravel5.4
composercreate-projectlaravel/laravelzcms5.4
2.安装Socialite
composerrequirelaravel/socialite
3.配置
编辑config/app.php
'providers'=>[ //其它服务提供者... Laravel\Socialite\SocialiteServiceProvider::class, ],
'aliases'=>[ 'Socialite'=>Laravel\Socialite\Facades\Socialite::class, ]
编辑config/service.php
'github'=>[ 'client_id'=>env('GITHUB_CLIENT_ID'), 'client_secret'=>env('GITHUB_CLIENT_SECRET'), 'redirect'=>env('GITHUB_REDIRECT'), ],
4.申请githuboauthapps
①.登录github->settings->OAuthApps
②.填写HomepageURL(网站域名http://www.zcms.site),AuthorizationcallbackURL(回调路径http://www.zcms.site/github/login)
③.复制client_id,client_secret到.env文件
GITHUB_CLIENT_ID=211a7aa4b9c5a3a4c10c
GITHUB_CLIENT_SECRET=2d3174561e440ed887a604f571aff9fa5bd84e44
GITHUB_REDIRECT=http://www.zcms.site/github/login
5.使用
①.添加路由
Route::get('/login','LoginController@github'); Route::get('/github.login','LoginController@githubLogin');//这里为刚才的回调路径
②.创建Controller
App\Http\Controllers创建LoginController.php
redirect(); } publicfunctiongithubLogin() { $user=Socialite::driver('github')->user(); dd($user); } }
6.见证奇迹吧
访问www.zcms.site/login。竟然跳转到了github,确认之后返回www.zcms.site/github/login?code=乱七八糟
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。