PHP code example of wenprise / socialite

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

    

wenprise / socialite example snippets




use Wenprise\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();



use Wenprise\Socialite\SocialiteManager;

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

$socialite = new SocialiteManager($config);

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

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

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


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

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

$socialite->setRequest($request);

$request = $socialite->getRequest();

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

PHP >= 7.0