PHP code example of professionalweb / socialite

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

    

professionalweb / socialite example snippets



use Overtrue\Socialite\SocialiteManager;

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

$socialite = new SocialiteManager($config);

$response = $socialite->driver('github')->redirect();

echo $response;// or $response->send();



// ...
$user = $socialite->driver('github')->user();

$user->getId();        // 1472352
$user->getNickname();  // "overtrue"
$user->getName();      // "安正超"
$user->getEmail();     // "[email protected]"
...

$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()

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


$request = new Request(); // or use AnotherCustomRequest.

$socialite = new SocialiteManager($config, $request);

$socialite->setRequest($request);

$request = $socialite->getRequest();

$session = new YouCustomSessionManager();
$socialite->getRequest()->setSession($session);

PHP >= 5.4