src/Auth/HybridAuthAuthenticate.php
protected function _getUser($adapter)
    {
        try {
            $providerProfile = $adapter->getUserProfile();
            $this->adapter($adapter);
            $this->profile($providerProfile);
        } catch (\Exception $e) {
            $adapter->logout();
            throw $e;
        }

        $config = $this->_config;
        $userModel = $this->_userModel;

        $user = null;
        $profile = $this->_query($providerProfile->identifier)->first();

        if ($profile) {
            $userId = $profile->get($config['profileModelFkField']);
            $user = $this->_userModel->find($config['finder'])
                ->where([
                    $userModel->aliasField($userModel->primaryKey()) => $userId
                ])
                ->first();

            // User record exists but finder conditions did not match,
            // so just update social profile record and return false.
            if (!$user) {
                $profile = $this->_profileEntity($profile);
                if (!$this->_profileModel->save($profile)) {
                    throw new \RuntimeException('Unable to save social profile.');
                }

                return false;
            }
        } elseif ($providerProfile->email) {
            $user = $this->_userModel->find($config['finder'])
                ->where([
                    $this->_userModel->aliasField($config['fields']['email']) => $providerProfile->email
                ])
                ->first();
        }

        $profile = $this->_profileEntity($profile);
        if (!$user) {
            $user = $this->_newUser($profile);
        }

        $profile->{$config['profileModelFkField']} = $user->{$userModel->primaryKey()};
        $profile = $this->_profileModel->save($profile);
        if (!$profile) {
            throw new \RuntimeException('Unable to save social profile.');
        }

        $user->set('social_profile', $profile);
        $user->unsetProperty($config['fields']['password']);

        return $user->toArray();
    }
protected function _getUser($adapter)
    {
        try {
            $providerProfile = $adapter->getUserProfile();
            $this->adapter($adapter);
            $this->profile($providerProfile);
        } catch (\Exception $e) {
            $adapter->logout();
            throw $e;
        }

        $config = $this->_config;
        $userModel = $this->_userModel;

        $user = null;
        $profile = $this->_query($providerProfile->identifier)->first();

        if ($profile) {
            $userId = $profile->get($config['profileModelFkField']);
            $user = $this->_userModel->find($config['finder'])
                ->where([
                    $userModel->aliasField($userModel->primaryKey()) => $userId
                ])
                ->first();

            // User record exists but finder conditions did not match,
            // so just update social profile record and return false.
            if (!$user) {
                $profile = $this->_profileEntity($profile);
                if (!$this->_profileModel->save($profile)) {
                    throw new \RuntimeException('Unable to save social profile.');
                }

                return false;
            }
        } elseif ($providerProfile->email) {
            $user = $this->_userModel->find($config['finder'])
                ->where([
                    $this->_userModel->aliasField($config['fields']['email']) => $providerProfile->email
                ])
                ->first();
        }

        $profile = $this->_profileEntity($profile);
        if (!$user) {
            $user = $this->_newUser($profile);
        }

        $profile->{$config['profileModelFkField']} = $user->{$userModel->primaryKey()};
        $profile = $this->_profileModel->save($profile);
        if (!$profile) {
            throw new \RuntimeException('Unable to save social profile.');
        }

        $user->set('social_profile', $profile);
        $user->unsetProperty($config['fields']['password']);

        return $user->toArray();
    }
protected function _getUser ( $ adapter ) { try { $ providerProfile = $ adapter -> getUserProfile ( ) ; $ this -> adapter ( $ adapter ) ; $ this -> profile ( $ providerProfile ) ; } catch ( \ Exception $ e ) { $ adapter -> logout ( ) ; throw $ e ; } $ config = $ this -> _config ; $ userModel = $ this -> _userModel ; $ user = null ; $ profile = $ this -> _query ( $ providerProfile -> identifier ) -> first ( ) ; if ( $ profile ) { $ userId = $ profile -> get ( $ config [ 'profileModelFkField' ] ) ; $ user = $ this -> _userModel -> find ( $ config [ 'finder' ] ) -> where ( [ $ userModel -> aliasField ( $ userModel -> primaryKey ( ) ) => $ userId ] ) -> first ( ) ; // User record exists but finder conditions did not match, // so just update social profile record and return false. if ( ! $ user ) { $ profile = $ this -> _profileEntity ( $ profile ) ; if ( ! $ this -> _profileModel -> save ( $ profile ) ) { throw new \ RuntimeException ( 'Unable to save social profile.' ) ; } return false ; } } elseif ( $ providerProfile -> email ) { $ user = $ this -> _userModel -> find ( $ config [ 'finder' ] ) -> where ( [ $ this -> _userModel -> aliasField ( $ config [ 'fields' ] [ 'email' ] ) => $ providerProfile -> email ] ) -> first ( ) ; } $ profile = $ this -> _profileEntity ( $ profile ) ; if ( ! $ user ) { $ user = $ this -> _newUser ( $ profile ) ; } $ profile -> { $ config [ 'profileModelFkField' ] } = $ user -> { $ userModel -> primaryKey ( ) } ; $ profile = $ this -> _profileModel -> save ( $ profile ) ; if ( ! $ profile ) { throw new \ RuntimeException ( 'Unable to save social profile.' ) ; } $ user -> set ( 'social_profile' , $ profile ) ; $ user -> unsetProperty ( $ config [ 'fields' ] [ 'password' ] ) ; return $ user -> toArray ( ) ; }
Get user record for HybridAuth adapter and try to get associated user record
from your application's database.

If app user record is not found a 'HybridAuth.newUser' event is dispatched
with profile info from HyridAuth. The event listener should create associated
user record and return user entity as event result.

@param \Hybrid_Provider_Model $adapter Hybrid auth adapter instance.
@return array User record
@throws \Exception Thrown when a profile cannot be retrieved.
@throws \RuntimeException If profile entity cannot be persisted.
Get user record for HybridAuth adapter and try to get associated user record from your application s database .