PHP code example of xbing2002 / socialite

1. Go to this page and download the library: Download xbing2002/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/ */

    

xbing2002 / socialite example snippets




use Overtrue\Socialite\SocialiteManager;

$config = [
    'wechat' => [
        'client_id'     => 'your-app-id',
        'client_secret' => 'your-app-secret',
        'redirect'      => 'http://localhost/socialite/callback.php',
    ],
];

$socialite = new SocialiteManager($config);

$socialite->driver('wechat')->redirect();




use Overtrue\Socialite\SocialiteManager;

$config = [
    'wechat' => [
        'client_id' => 'your-app-id',
        'client_secret' => 'your-app-secret',
        'redirect' => 'http://localhost/socialite/callback.php',
    ],
];

$socialite = new SocialiteManager($config);

$user = $socialite->driver('wechat')->user();

$user->getId();        // openid
$user->getNickname();  // "昵称"
$user->getName();      // "昵称"
$user->getAvatar();     // 头像
$user->getProviderName(); // WeChat
...

$response = $socialite->driver('github')
                ->scopes(['scope1', 'scope2'])->redirect();


$socialite->redirect($url);
// or
$socialite->withRedirectUrl($url)->redirect();
// or
$socialite->setRedirectUrl($url)->redirect();

$response = $socialite->driver('google')
                    ->with(['hd' => 'example.com'])->redirect();


$user = $socialite->driver('weibo')->user();

$user['id'];        // 1472352
$user['nickname'];  // "overtrue"
$user['name'];      // "安正超"
$user['email'];     // "[email protected]"
...

$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();
$user->getOriginal();
$user->getToken();// or $user->getAccessToken()
$user->getProviderName(); // GitHub/Google/Facebook...

$accessToken = new AccessToken(['access_token' => $accessToken]);
$user = $socialite->user($accessToken);