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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Jlink或者stlink用于SWD接口下载程序

    Jlink或者stlink用于SWD接口下载程序最近要使用stm32f103c8t6最小系统板,直接ISP串口下载程序太麻烦,就想着使用swd接口来调试。结果:通过SWD接口下载程序成功,但调试失败,还不知原因,会的的人麻烦交流一下。SWD接口:3.3VDIO(数据)CLK(时钟)GND1.首先声明jlink和stlink都有jtag和swd调试功能。jlink接口如下:如图,我使用的就是VCC…

    2022年4月25日
    56
  • ORACLE 的触发器类型有哪些,ORACLE触发器类型

    ORACLE 的触发器类型有哪些,ORACLE触发器类型1.DML触发器由对表的INSERT,DELETE,UPDATE激发CREATEORREPLACETRIGGERtrigger_nameAFTER–TIMING:BEFOREORAFTERDELETEORINSERTORUPDATEONtable_name–STATEMENT–REFERE…

    2022年7月11日
    16
  • XSS攻击拦截_struts拦截器作用

    XSS攻击拦截_struts拦截器作用struts2拦截器添加及xss攻击的处理

    2022年9月27日
    2
  • 深入理解Java虚拟机:垃圾收集

    深入理解Java虚拟机:垃圾收集概述    GC即垃圾回收,是指jvm用于释放那些不再使用的对象所占用的内存。    垃圾收集的目的在于清除不再使用的对象。gc通过确定对象是否被活动对象引用来确定是否收集该对象。两种常用的方法是引用计数和对象引用遍历。JVM的GC触发原理    JVM的GC主要是对堆内存的回收,一般把新生代的GC称为minorGC,把老年代的GC成为fullGC,所谓fullgc会先出发一次minor

    2022年5月14日
    33
  • 宽度学习与深度学习中的时空转化问题

    宽度学习与深度学习中的时空转化问题ž在自然界中运动是绝对的,静止是相对的。这句话也说明了深度学习过去、现在、未来。由于我发现山东大学有个组和澳门大学陈俊龙团队的宽度学习、极限学习等。目前由于神经网络是黑盒研究、所以很多人利用反卷积和卷积可视化来解释这种微分和积分的编程,由于冗余和稀疏特性使用微积分或者差分求导数和偏导是必然。宽度学习文章和代码研究地址:http://www.broadlearning.ai在深度学习上目…

    2022年5月21日
    43
  • 群晖 VMM虚拟机安装windows XP[通俗易懂]

    群晖 VMM虚拟机安装windows XP[通俗易懂]群晖VMM虚拟机安装windowsXP。作为微软历史上最成功的操作系统之一,推出的10余年来,其应用十分广泛,拥有庞大的用户群体。

    2022年8月16日
    3

发表回复

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

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