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


'providers' => [
    // Other service providers...

    Saeedvir\SocialiteSlim\SocialiteServiceProvider::class,
],

'aliases' => [
    // Other aliases...

    'Socialite' => Saeedvir\SocialiteSlim\Facades\Socialite::class,
    'OAuth' => Saeedvir\SocialiteSlim\Facades\OAuth::class,
],

'google' => [
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' => 'http://your-callback-url',
],

'github' => [
    'client_id' => env('GITHUB_CLIENT_ID'),
    'client_secret' => env('GITHUB_CLIENT_SECRET'),
    'redirect' => 'http://your-callback-url',
],

'telegram' => [
    'client_id' => env('TELEGRAM_CLIENT_ID'),
    'client_secret' => env('TELEGRAM_CLIENT_SECRET'),
    'redirect' => 'http://your-callback-url',
],



namespace App\Http\Controllers\Auth;

use Saeedvir\SocialiteSlim\Facades\Socialite;

class AuthController extends Controller
{
    /**
     * Redirect the user to the GitHub authentication page.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('github')->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return \Illuminate\Http\Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('github')->user();

        // $user->token
    }
}



namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Saeedvir\SocialiteSlim\Traits\HasOAuthConnections;

class User extends Authenticatable
{
    use HasOAuthConnections;
    
    // ... rest of your model
}

use Saeedvir\SocialiteSlim\Facades\OAuth;

// Find or create an OAuth connected user
$connectedUser = OAuth::findOrCreateOauthUser($provider, $providerId, $userData);
bash
php artisan vendor:publish --provider="Saeedvir\SocialiteSlim\SocialiteServiceProvider" --tag="socialite-migrations"
bash
php artisan migrate