PHP code example of efureev / social

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

    

efureev / social example snippets



return [
    'drivers' => [
        'vk' => [
            'clientId' => env('VK_CLIENT_ID'),
            'clientSecret' => env('VK_CLIENT_SECRET'),
        ],
        'github' => [
            // ...
        ],
        // ...
    ],
];



return [
    'onSuccess' => function ($driver) {
        $user = \Fureev\Social\Services\SocialAccountService::setOrGetUser($driver);

        return \Fureev\Social\Services\SocialAccountService::auth($user);
    },
    //'onSuccess' => [\App\Http\Controllers\IndexController::class, 'index'],
    'drivers'   => [
        'gitlab' => [
            'enabled'  => false,
            'provider' => \Fureev\Socialite\Two\GitlabProvider::class,
            //            'enabled'  => false,
            'label'    => '<i class="fab fa-gitlab"></i>'
        ],
        'vk'     => [
            // 'enabled'  => false,
            'label'        => '<i class="fab fa-vk"></i>',
            'clientId'     => env('VK_CLIENT_ID'),
            'clientSecret' => env('VK_CLIENT_SECRET'),
        ],
        'github' => [
            'enabled' => false,
            'label'   => '<i class="fab fa-github-alt"></i>'
        ],
        'custom_auth' => [
            'clientId' => env('SOCIAL_AUTH_CLIENT_ID'),
            'clientSecret' => env('SOCIAL_AUTH_CLIENT_SECRET'),
            'url_auth' => 'http://api.auth.x/auth/authorize',
            'url_token' => 'http://api.auth.x/auth/token',
            'userInfoUrl' => 'http://api.auth.x/users/info',
            'scopeSeparator' => ',',
            'scopes' => ['name','email','photo'],
            'tokenFieldsExtra' => [
                'grant_type' => 'authorization_code',
            ],
            'mapFields' =>
                [
                    'id' => 'id',
                    'name' => ['profile.first_name.v', new \Fureev\Socialite\Separator, 'profile.last_name.v'],
                    'email' => 'profile.email.v',
                    'avatar' => 'photo',
                    'nickname' => 'id',
                    'profileId' => 'profileId',
                ],
            'guzzle' => [
                'query' => [
                    'prettyPrint' => 'false',
                ],
                'headers' => [
                    'Accept' => 'application/json',
                    'Authorization' => 'Bearer {{%TOKEN%}}',
                ],
            ],
        ],
        'google' => [
            // 'enabled'      => false,
            'clientId'         => env('G+_CLIENT_ID'),
            'clientSecret'     => env('G+_CLIENT_SECRET'),
            'url_token'        => 'https://accounts.google.com/o/oauth2/token',
            'url_auth'         => 'https://accounts.google.com/o/oauth2/auth',
            'userInfoUrl'      => 'https://www.googleapis.com/plus/v1/people/me?',
            'label'            => '<i class="fab fa-google"></i>',
            //            'onSuccess'        => [\App\Http\Controllers\HomeController::class, 'index'],
            'scopeSeparator'   => ' ',
            'scopes'           => ['openid', 'profile', 'email',],
            'tokenFieldsExtra' => [
                'grant_type' => 'authorization_code'
            ],
            'mapFields'        =>
                [
                    'id'     => 'id',
                    'name'   => 'displayName',
                    'email'  => 'emails.0.value',
                    'avatar' => 'image.url',
                ],
            'guzzle'           => [
                'query'   => [
                    'prettyPrint' => 'false',
                ],
                'headers' => [
                    'Accept'        => 'application/json',
                    'Authorization' => 'Bearer {{%TOKEN%}}',
                ],
            ]
        ]
    ]
];


 
use Fureev\Socialite\Contracts\Provider as ProviderContract;
class SocialAccountService
{
    public static function setOrGetUser(ProviderContract $provider)
    {
        $providerUser = $provider->user();

        $providerName = $provider->getName();

        //...

    }
}