PHP code example of saeedvir / socialite-slim

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

    

saeedvir / socialite-slim example snippets


use Saeedvir\SocialiteSlim\Socialite;

// Redirect user to OAuth provider
return Socialite::driver('google')->redirect();

// Get user information from provider callback
$user = Socialite::driver('google')->user();

// Get specific user data
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

use Saeedvir\SocialiteSlim\Facades\OAuth;

// Find or create an OAuth connected user
$oauthUser = OAuth::findOrCreateOauthUser(
    'google',
    $user->getId(),
    [
        'access_token' => $user->token,
        'refresh_token' => $user->refreshToken,
        'expires_in' => $user->expiresIn,
        'name' => $user->name,
        'email' => $user->email,
        'avatar' => $user->avatar
    ]
);

// Check if user has OAuth connection
$hasConnection = OAuth::userHasOauthConnection($userModel, 'google');

// Get OAuth user by provider and ID
$storedOauthUser = OAuth::getOauthUser('google', $googleUserId);

// Add additional scopes
Socialite::driver('google')
    ->scopes(['openid', 'profile', 'email', 'https://www.googleapis.com/auth/calendar'])
    ->redirect();

// Add custom parameters
Socialite::driver('google')
    ->with(['hd' => 'example.com']) // Google Apps domain restriction
    ->redirect();

use Saeedvir\SocialiteSlim\Socialite;
use Saeedvir\SocialiteSlim\Testing\SocialiteFake;

// In your tests:
Socialite::fake();

// Define a fake user for GitHub
Socialite::fake('github', (object) [
    'id' => '12345',
    'nickname' => 'githubuser',
    'name' => 'GitHub User',
    'email' => '[email protected]',
]);

// Now Socialite::driver('github')->user() will return the fake user above
bash
php artisan vendor:publish --provider="Saeedvir\SocialiteSlim\SocialiteServiceProvider" --tag="socialite-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Saeedvir\SocialiteSlim\SocialiteServiceProvider" --tag="socialite-config"