PHP code example of mmfei / hyperf-socialite

1. Go to this page and download the library: Download mmfei/hyperf-socialite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mmfei / hyperf-socialite example snippets




return [
    'facebook' => [
        'client_id' => '',
        'client_secret' => '',
        // 其他provider中需要使用的配置
        // ...
    ]   
    // qq,weixin...    
];



return [
    HyperfSocialiteProviders\Facebook\FacebookExtendSocialite::class,
];




use Cblink\Hyperf\Socialite\Contracts\SocialiteInterface;

class Controller 
{
    
    /**
    * @param SocialiteInterface $socialite
     * @return \Hyperf\HttpServer\Contract\ResponseInterface
     */
    public function redirectToProvider(SocialiteInterface $socialite)
    {
        // 重定向跳转
       $redirect = $socialite->driver('facebook')->redirect();
       
       // 使用新的配置跳转
       $socialite->driver('facebook')->setConfig([
            'client_id' => 'xxx',
            'client_secret' => 'xxxx',
       ])  
       
       return $redirect; 
    }
    
    /**
    * @param SocialiteInterface $socialite
    */
    public function handleProviderCallback(SocialiteInterface $socialite)
    {
        // 获取用户信息
       $user = $socialite->driver('facebook')->user();
       
       //
       // $user->token;
    }


}


php 7.4 + hyperf 2.2  v0.0.3
php 7.4 + hyperf 2.1  v0.0.2
php 7.4 + hyperf 2.0  v0.0.1
shell

# 安装
composer hp bin/hyperf.php vendor:publish mmfei/hyperf-socialite