PHP code example of hobbii / socialite-provider

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

    

hobbii / socialite-provider example snippets




use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

class AuthController extends Controller
{
    public function redirect(): RedirectResponse
    {
        return Socialite::driver('hobbii')->redirect();
    }
    
    public function callback(Request $request): RedirectResponse
    {
        $hobbiiUser = Socialite::driver('hobbii')->user();
        
        $user = User::updateOrCreate([
            'email' => $hobbiiUser->getEmail(),
        ], [
            'first_name' => Arr::get($hobbiiUser->user, 'first_name'),
            'last_name' => Arr::get($hobbiiUser->user, 'last_name'),
            'token' => $hobbiiUser->token,
            'refresh_token' => $hobbiiUser->refreshToken,
        ]);
        
        Auth::login($user);
        
        $request->session()->regenerate();

        return redirect()->intended('/');
    }
}
shell
php artisan vendor:publish --provider="Hobbii\SocialiteProvider\SocialiteServiceProvider" --tag=config