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

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 语音合成的思路、语音的声学特征、声音采样的一些资料

    语音合成的思路、语音的声学特征、声音采样的一些资料语音合成:把语音波形文件重现,以一种灵活的方式,只用极少数的基础数据,比如元音辅音的语音参数,那么首先需要研究元音辅音的语音学性质。先从元音开始,根据相关资料,不同的元音是由相同的原始声带音通过不同的共振腔(由声腔形状的变化决定)产生不同的共振效果,导致其频谱发生很大变化而得以区分。一般来说每个频谱都有三个振幅比较强的频率区,在频谱上呈现为波峰状,称为“共振峰”(formant),从低频到高频

    2022年6月26日
    38
  • <artifactId>ojdbc8</artifactId>「建议收藏」

    spring-boot-starter-parent作用在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么staterpoms,它可以提供dependencymanagement,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,后面可以看到。spring-boot-starter-web作用springweb核心组件spring-boot-maven-plugin作用如果我们要直接Main启动sprin

    2022年4月16日
    78
  • 使用FileReader对象的readAsDataURL方法来读取图像文件

    使用FileReader对象的readAsDataURL方法来读取图像文件readAsDataURL方法会使用base-64进行编码,编码的资料由data字串开始,后面跟随的是MIMEtype,然后再加上base64字串,逗号之后就是编码过的图像文件的内容。data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAA……使用

    2025年7月30日
    2
  • python+Django+Mysql+协同过滤电影推荐系统简介

    python+Django+Mysql+协同过滤电影推荐系统简介电影推荐系统技术采用前端:bootstrap3+vue+jquery后端:django2.2.1+djangorestframework(MVC框架)数据库:mysql数据集:豆瓣数据集+豆瓣电影爬虫+csv存储movielens数据集+图片+用户数据和评分数据+csv存储功能介绍录入电影信息用户打分电影标签分类电影推荐电影分享电影收藏后台管理系统。算法基于用户的协同过滤算法:协同过滤,根据用户的打分来进行推荐。从所有打分的用户中找

    2022年6月11日
    40
  • 【STM32】HAL库 STM32CubeMX教程六—-定时器中断

    【STM32】HAL库 STM32CubeMX教程六—-定时器中断前言:今天我们来学习定时器,32的定时器有着非常丰富的功能,输入捕获/输出比较,PWM,中断等等。是我们学习STM32最频繁使用到的外设之一,所以一定要掌握好,这节我们讲解定时器中断,本系列教程将对应外设原理,HAL库与STM32CubeMX结合在一起讲解,使您可以更快速的学会各个模块的使用所用工具:1、芯片:STM32F407ZET6/STM32F103ZET62、ST…

    2022年5月27日
    100
  • 如何通过eclipse导入web项目「建议收藏」

    如何通过eclipse导入web项目「建议收藏」如何通过eclipse导入web项目通过eclipse导入web项目的相关流程。【1】打开eclipse,单击左上角的File,File–>Import【2】打开General–>ExistingprojectsintoWorkspace–>Browse(选择需要打开的项目)注意:记得勾选下方【copyprojectintoproject】【3】所有不是在自己电脑上开发的web项目,都需要重新配置一下,单击项目右键,打开Projects【4】打开JavaBul

    2022年4月20日
    153

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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