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\SocialiteServiceProvider from your providers[] array in config\app.php if you have added it already.

  • Add \SocialiteProviders\Manager\ServiceProvider::class to your providers[] array in config\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\SocialiteWasCalled event to your listen[] array in app/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

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 第三方登录的更多相关文章

  1. 使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样

    使用QQ第三方登录时,手机应用和网站应用对同一个QQ号,获取到的openid不一样openid生成是根据应用的appid和QQ号的一些信息加密生成,对于一个appid和QQ号来说,openid是唯一的 ...

  2. 【第三方登录】之QQ第三方登录

    最近公司做了个网站,需要用到第三方登录的东西.有QQ第三方登录,微信第三方登录.先把QQ第三方登录的代码列一下吧. public partial class QQBack : System.Web.U ...

  3. QQ第三方登录

    QQ第三方登录 在Android应用程序的开发过程中,很多时候需要加入用户登录/注册模块.除了自己动手设计登录界面并实现相应功能外,现在还可以借助百度.腾讯等开发者平台提供的第三方账号登录模块.最近研 ...

  4. PHP实现QQ第三方登录

    PHP实现QQ第三方登录 学习之前,请大家先看一下oAuth协议. 首先呢,我们进入QQ互联的官方网站 http://connect.qq.com登入我们自己的QQ号,没有QQ号的小伙伴可以忽略本篇博 ...

  5. 利用JS_SDK实现QQ第三方登录

    前言 现如今,第三方登录已成为大部分网站必备的一项基础技能,引入时髦的第三方登录不仅能帮你吸引更多的用户,也让你的网站可以充分利用其他大型网站的用户资源.本次教程将让你的网站最快捷便利地引入QQ登录. ...

  6. web实现QQ第三方登录

    开放平台-web实现QQ第三方登录   应用场景     web应用通过QQ登录授权实现第三方登录.   操作步骤     1  注册成为QQ互联平台开发者,http://connect.qq.com ...

  7. Android 实现QQ第三方登录

    Android 实现QQ第三方登录 在项目中需要实现QQ第三方登录,经过一番努力算是写出来了,现在总结以下,以防以后遗忘,能帮到其他童鞋就更好了. 首先肯定是去下载SDK和DEMO http://wi ...

  8. Android应用之——最新版本号SDK V2.4实现QQ第三方登录

    为什么要写这篇博客呢?由于.我在做这个第三方登录的时候,找了非常多资料,发现要么就是过时了.要么就是说的非常不清楚.非常罗嗦.并且非常多都是一些小demo,不是什么实例.甚至连腾讯官方的文档都有这个问 ...

  9. Django项目中使用qq第三方登录。

    使用qq登录的前提是已经在qq互联官网创建网站应用并获取到QQ互联中网站应用的APP ID和APP KEY 1,建路由 # qq登录 path('loginQq/',qq.loginQq,name=' ...

随机推荐

  1. 【JZOJ5233】【GDOI模拟8.5】概率博弈 树形dp+期望

    题面 小A和小B在玩游戏.这个游戏是这样的: 有一棵n个点的以1为根的有根树,叶子有权值.假设有m个叶子,那么树上每个叶子的权值序列就是一个1->m 的排列. 一开始在1号点有一颗棋子.两人轮流 ...

  2. Java图片高保真缩放工具类

    Java图片高保真缩放 package com.xindai.auth.service.util; import java.awt.image.BufferedImage; import java.i ...

  3. db link的查看创建与删除 1

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...

  4. Breakpoint 断点只生效一次

  5. Codefroces 213E. Two Permutations

    E. Two Permutations time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. 关闭防火墙,仍然无法访问80端口 centos

    如果你用的是阿里云,那么需要添加80端口开放才行,在云服务器-安全组-添加安全组

  7. 举例分析private的作用【c/c++学习】

    抛砖引玉: c++中private的用处 我知道我们可以用 public 中的值,把private中的数据给提出来,但是还是搞不懂private该怎么用,或者说在一个具体程序中,private有什么用 ...

  8. JavaScript 报错 注释

  9. ML面试1000题系列(51-60)

    本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 51.简单说下sigmoid激活函数 常用的非线 ...

  10. 基于遗传算法(Genetic Algorithm)的TSP问题求解(C)

    基于遗传算法的TSP问题求解(C) TSP问题: TSP(Travelling salesman problem): 译作“旅行商问题”, 一个商人由于业务的需要,要到n个城市,每个城市之间都有一条路 ...