PHP code example of larva / laravel-passport-socialite

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

    

larva / laravel-passport-socialite example snippets


'providers' => [
    // Other service providers...
    Larva\Passport\Socialite\PassportSocialiteGrantProvider::class,
],

namespace App\Models;

class User extends Authenticatable {
    
    use HasApiTokens, Notifiable;

    /**
    * Find user using social provider's user
    * 
    * @param string $provider Provider name as requested from oauth e.g. facebook
    * @param \Larva\Socialite\Contracts\User $socialUser User of social provider
    *
    * @return User|void
    */
    public static function findAndValidateForPassportSocialiteRequest(string $provider, \Larva\Socialite\Contracts\User $socialUser) {
        if( $socialUser->user) {
            return $socialUser->user;
        }
        
        // 你其他代码,例如自动注册用户 如果你绑定了用户 \Larva\Socialite\Contracts\User 里面有你绑定的用户模型实例
        return;
    }
}