laravel5.6 QQ 第三方登录

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\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

  • Laravel docs on configuration

  • 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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/113037.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • excel旭日图_旭日图怎么画

    excel旭日图_旭日图怎么画旭日图(Sunburst)由多层的环形图组成,在数据结构上,内圈是外圈的父节点。因此,它既能像饼图一样表现局部和整体的占比,又能像矩形树图一样表现层级关系。引入相关文件旭日图是ApacheEChartsTM4.0新增的图表类型,从CDN引入完整版的echarts.min.js最简单的旭日图创建旭日图需要在series配置项中声明类型为‘sunburst’的系列,并且以树形结构声明其data:varoption={series:{type

  • PMF 培训[通俗易懂]

    PMF 培训[通俗易懂]IBM有一些很有名的培训,也很有效,真的是有立竿见影的效果.过去很长时间之后,可能不记得培训的那些细节,但是培训中传达的工作方式,能给你很大的影响.进公司后3个月的时候接受了第一个,有关customerfacing的,其实是为你提供了一个商务沟通的基本模式,现在培训的内容忘记了,但是这个模式还记得:调查-承诺-执行-反馈.一个有效的商务沟通,哪怕是和客户的一个电话,都需要艺…

  • pycharm如何编译程序_xc8编译器

    pycharm如何编译程序_xc8编译器现在轮到PyCharmPyCharm安装教程PyCharm是一款功能强大的Python编辑器,具有跨平台性,鉴于目前最新版PyCharm使用教程较少,为了节约时间,来介绍一下PyCharm在Windows下是如何安装的。第一步:进入PyCharm官网这是PyCharm的下载地址:http://www.jetbrains.com/pycharm/download/#section=windows进入该网站后,我们会看到如下界面:professional表示专业版,co

  • SQLServer2K远程连接问题解决方案(转载自飞狐小屋)

    SQLServer2K远程连接问题解决方案(转载自飞狐小屋)由于特定需求,最近实验室需要远程连接外地的sqlserver2000服务器,最开始怎么连也连不上,出现了很多问题,但是在今天上午,借用实验室的测试条件(一个公网IP,两个教育网静态IP),终于调试通过,也算是完成了老师的任务,在这里写下自己的心得,参考了很多网上的文章和论坛里的问题,希望对有此需要的有帮助。不完善之处,也请留言。废话少说,进入主题。步骤:一看ping服务…

  • jetbrains系列软件汉化图文教程

    idea 激活码,jetbrains系列软件汉化图文教程

  • Linux常用命令面试题(linux面试题必会题目)

    Linux常用命令因为热爱,所以拼搏。–RuiDer常用指令ls  显示文件或目录-l列出文件详细信息l(list)-a列出当前目录下所有文件及目录,包括隐藏的a(all)mkdir创建目录-p创建目录,若…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号