laravel5.6 QQ 第三方登录
https://socialiteproviders.github.io/providers/qq.html
1. Installation
// This assumes that you have composer installed globally
composer require socialiteproviders/qq
# 2. Service Provider
Remove
Laravel\Socialite\SocialiteServiceProviderfrom yourproviders[]array inconfig\app.phpif you have added it already.Add
\SocialiteProviders\Manager\ServiceProvider::classto yourproviders[]array inconfig\app.php.
For example:
'providers' => [
// a whole bunch of providers
// remove 'Laravel\Socialite\SocialiteServiceProvider',
\SocialiteProviders\Manager\ServiceProvider::class, // add
];
- Note: If you would like to use the Socialite Facade, you need to install it.
# 3. Event Listener
Add
SocialiteProviders\Manager\SocialiteWasCalledevent to yourlisten[]array inapp/Providers/EventServiceProvider.Add your listeners (i.e. the ones from the providers) to the
SocialiteProviders\Manager\SocialiteWasCalled[]that you just created.The listener that you add for this provider is
'SocialiteProviders\\QQ\\QqExtendSocialite@handle',.Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
For example:
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'SocialiteProviders\\QQ\\QqExtendSocialite@handle',
],
];
# Reference
# 4. Configuration setup
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command artisan config:cache) all config is still available.
# Add to config/services.php.
'qq' => [
'client_id' => env('QQ_KEY'),
'client_secret' => env('QQ_SECRET'),
'redirect' => env('QQ_REDIRECT_URI')
],
# 5. Usage
You should now be able to use it like you would regularly use Socialite (assuming you have the facade installed):
return Socialite::with('QQ')->redirect();
# Lumen Support
You can use Socialite providers with Lumen. Just make sure that you have facade support turned on and that you follow the setup directions properly.
Note: If you are using this with Lumen, all providers will automatically be stateless since Lumen does not keep track of state.
Also, configs cannot be parsed from the services[] in Lumen. You can only set the values in the .env file as shown exactly in this document. If needed, you can also override a config (shown below).
# Stateless
- You can set whether or not you want to use the provider as stateless. Remember that the OAuth provider (Twitter, Tumblr, etc) must support whatever option you choose.
Note: If you are using this with Lumen, all providers will automatically be stateless since Lumen does not keep track of state.
// to turn off stateless
return Socialite::with('QQ')->stateless(false)->redirect(); // to use stateless
return Socialite::with('QQ')->stateless()->redirect();
# Overriding a config
If you need to override the provider's environment or config variables dynamically anywhere in your application, you may use the following:
$clientId = "secret";
$clientSecret = "secret";
$redirectUrl = "http://yourdomain.com/api/redirect";
$additionalProviderConfig = ['site' => 'meta.stackoverflow.com'];
$config = new \SocialiteProviders\Manager\Config($clientId, $clientSecret, $redirectUrl, $additionalProviderConfig);
return Socialite::with('QQ')->setConfig($config)->redirect();
# Retrieving the Access Token Response Body
Laravel Socialite by default only allows access to the access_token. Which can be accessed via the \Laravel\Socialite\User->token public property. Sometimes you need access to the whole response body which may contain items such as a refresh_token.
You can get the access token response body, after you called the user() method in Socialite, by accessing the property $user->accessTokenResponseBody;
$user = Socialite::driver('QQ')->user();
$accessTokenResponseBody = $user->accessTokenResponseBody;
# Reference
参考地址:https://laravel-china.org/docs/laravel/5.6/socialite/1418
https://socialiteproviders.github.io/providers/qq.html
laravel5.6 QQ 第三方登录的更多相关文章
- 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样
使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样openid生成是根据应用的appid和QQ号的一些信息加密生成,对于一个appid和QQ号来说,openid是唯一的 ...
- 【第三方登录】之QQ第三方登录
最近公司做了个网站,需要用到第三方登录的东西.有QQ第三方登录,微信第三方登录.先把QQ第三方登录的代码列一下吧. public partial class QQBack : System.Web.U ...
- QQ第三方登录
QQ第三方登录 在Android应用程序的开发过程中,很多时候需要加入用户登录/注册模块.除了自己动手设计登录界面并实现相应功能外,现在还可以借助百度.腾讯等开发者平台提供的第三方账号登录模块.最近研 ...
- PHP实现QQ第三方登录
PHP实现QQ第三方登录 学习之前,请大家先看一下oAuth协议. 首先呢,我们进入QQ互联的官方网站 http://connect.qq.com登入我们自己的QQ号,没有QQ号的小伙伴可以忽略本篇博 ...
- 利用JS_SDK实现QQ第三方登录
前言 现如今,第三方登录已成为大部分网站必备的一项基础技能,引入时髦的第三方登录不仅能帮你吸引更多的用户,也让你的网站可以充分利用其他大型网站的用户资源.本次教程将让你的网站最快捷便利地引入QQ登录. ...
- web实现QQ第三方登录
开放平台-web实现QQ第三方登录 应用场景 web应用通过QQ登录授权实现第三方登录. 操作步骤 1 注册成为QQ互联平台开发者,http://connect.qq.com ...
- Android 实现QQ第三方登录
Android 实现QQ第三方登录 在项目中需要实现QQ第三方登录,经过一番努力算是写出来了,现在总结以下,以防以后遗忘,能帮到其他童鞋就更好了. 首先肯定是去下载SDK和DEMO http://wi ...
- Android应用之——最新版本号SDK V2.4实现QQ第三方登录
为什么要写这篇博客呢?由于.我在做这个第三方登录的时候,找了非常多资料,发现要么就是过时了.要么就是说的非常不清楚.非常罗嗦.并且非常多都是一些小demo,不是什么实例.甚至连腾讯官方的文档都有这个问 ...
- Django项目中使用qq第三方登录。
使用qq登录的前提是已经在qq互联官网创建网站应用并获取到QQ互联中网站应用的APP ID和APP KEY 1,建路由 # qq登录 path('loginQq/',qq.loginQq,name=' ...
随机推荐
- Docker Tomcat部署
1.下载tomcat镜像 docker pull tomcat 2.上传项目 /etc/tomcat/webapps/ 3.启动tomcat容器 docker run -d --name tomcat ...
- c++新特性实验(1)预处理
1.参考资料 1.1 C++ C++17 标准文档(正式) : https://www.iso.org/standard/68564.html C++ 标准文档(草案) : ht ...
- Poj 2104区间第k大(归并树)
题目链接 K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 36890 Accepted: 11860 C ...
- 常用css3属性
总结一下在工作用常用到的属性设置 1.设置文本的可选择性 -webkit-user-select:none/text 2.设置背景的绘制区域 background-clip:border-box/pa ...
- python第一天 :计算机基础(一)
1.什么是编程语言 答:人类与计算机交流的介质 2.什么是编程 答:利用编程语言控制计算机解决问题 3.为什么要编程 答:可以控制计算机做事,提高生产生活效率 4.计算机的五大组成部分分别有什么作用? ...
- github遇到 non-fast-forward错误
可以参考:这里 解决过程如图所示
- 【JZOJ4921】【NOIP2017提高组模拟12.10】幻魔皇
题目描述 幻魔皇拉比艾尔很喜欢斐波那契树,他想找到神奇的节点对. 所谓斐波那契树,根是一个白色节点,每个白色节点都有一个黑色节点儿子,而每个黑色节点则有一个白色和一个黑色节点儿子.神奇的节点对则是指白 ...
- Directx11教程(5) 画一个简单的三角形(1)
原文:Directx11教程(5) 画一个简单的三角形(1) 在本篇教程中,我们将通过D3D11画一个简单的三角形.在D3D11中,GPU的渲染主要通过shader来操作(当然还有一些操作 ...
- JavaScript--函数中()的作用
在函数中参数是函数的时候:function a(函数名) 与 function a(函数名()) 的区别: // 在函数里面() 是一个编组和立即执行的功能 /** * function autoPl ...
- 从零学React Native之12 组件的生命周期
一个React Native组件从它被加载,到最终被卸载会经历一个完整的生命周期.所谓生命周期,就是一个对象从开始生成到最后消亡所经历的状态,理解生命周期,是合理开发的关键. ES6语法和之前的ES5 ...
