Basically, each provider adapter has to define at least 4 methods:
Hybrid_Providers_{provider_name}::initialize()
Hybrid_Providers_{provider_name}::loginBegin()
Hybrid_Providers_{provider_name}::loginFinish()
Hybrid_Providers_{provider_name}::getUserProfile()
HybridAuth also come with three others models
Class Hybrid_Provider_Model_OpenID for providers that uses the OpenID 1 and 2 protocol.
Class Hybrid_Provider_Model_OAuth1 for providers that uses the OAuth 1 protocol.
Class Hybrid_Provider_Model_OAuth2 for providers that uses the OAuth 2 protocol.
/** * Naive getter of the current connected IDp API client * @return stdClass * @throws Exception */ function api() { if (!$this->adapter->isUserConnected()) { Hybrid_Logger::error("User not connected to the provider."); throw new Exception("User not connected to the provider.", 7); } return $this->adapter->api; }
/** * logout */ function logout() { $this->api->destroySession(); parent::logout(); }
public function logout() { if (!e107::getPref('social_login_active', false) || !$this->adapter || !Hybrid_Auth::isConnectedWith($this->getProvider())) { return true; } try { $this->adapter->logout(); $this->adapter = null; } catch (Exception $e) { return $e->getMessage(); } return true; }
/** * logout */ function logout() { $this->api->disconnect(); parent::logout(); }
/** * {@inheritdoc} */ function logout() { parent::logout(); }
/** * Init external user login/signup provider * @return e_system_user */ public function initProvider() { if (null !== $this->_provider) { return $this; } if ($this->get('user_xup')) { $providerId = $this->getProviderName(); require_once e_HANDLER . 'user_handler.php'; $this->_provider = new e_user_provider($providerId); $this->_provider->init(); } }
/** * 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. */ 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(); }
function __construct($providerId, $config, $params = null) { parent::__construct($providerId, $config, $params); $this->user = new UserProfile(); }
/** * logout */ function logout() { if ($this->session) { //$url = $this->helper->getLogoutUrl($this->session, "http://localhost.zendfactory.com/user/logout"); $baseUrl = Hybrid_Auth::$config['base_url']; $pos = strpos($baseUrl, "/social-auth"); $websiteURL = substr($baseUrl, 0, $pos); //$url = $this->helper->getLogoutUrl($this->session, "http://www.zendfactory.com/user/logout"); //$url = $this->helper->getLogoutUrl($this->session, "http://localhost.zendfactory.com/user/logout"); $url = $this->helper->getLogoutUrl($this->session, $websiteURL . "/user/logout"); parent::logout(); Hybrid_Auth::redirect($url); } }