Basically Hybrid_Provider_Adapter will create a bridge from your php
application to the provider api.
Hybrid_Auth will automatically load Hybrid_Provider_Adapter and create
an instance of it for each authenticated provider.
/** * Authenticates a user. * @throws Exception * @return boolean whether authentication succeeds. */ public function authenticate() { $params = array(); if (strtolower($this->provider) == 'openid') { $params['openid_identifier'] = $_GET['openid_identifier']; } $this->_hybridProviderAdapter = $this->hybridAuth->authenticate($this->provider, $params); if (!$this->_hybridProviderAdapter->isUserConnected()) { $this->errorCode = self::ERROR_PASSWORD_INVALID; return false; } /** @var AccountModule $account */ $account = Yii::app()->getModule('account'); $userHybridAuth = CActiveRecord::model($account->userHybridAuthClass)->findByAttributes(array($account->providerField => $this->provider, $account->identifierField => $this->_hybridProviderAdapter->getUserProfile()->identifier)); /** @var AccountUser $user */ $user = $userHybridAuth ? CActiveRecord::model($account->userClass)->findByPk($userHybridAuth->user_id) : false; if (!$user) { $this->errorCode = self::ERROR_USERNAME_INVALID; return false; } $this->_id = $user->primaryKey; if ($account->activatedField && !$user->{$account->activatedField}) { $this->errorCode = self::ERROR_NOT_ACTIVATED; return false; } if ($account->disabledField && $user->{$account->disabledField}) { $this->errorCode = self::ERROR_DISABLED; return false; } $this->_id = $user->id; $this->_hybridProviderAdapter = $this->_hybridProviderAdapter; $this->errorCode = self::ERROR_NONE; return true; }
public function testUserNotLinkedTo() { $userProfile = new \Hybrid_User_Profile(); $userProfile->identifier = null; $this->hybridAuthMock->method('authenticate')->willReturn(new \Hybrid_Provider_Adapter()); $this->authAdapterMock->method('getUserProfile')->willReturn($userProfile); $this->assertInstanceOf('\\Hybrid_Auth', $this->hybridAuthMock); $provider = new AuthProvider('Facebook'); $provider->setResponse($this->getApp()); $provider->setHybridauth($this->hybridAuthMock); $provider->setAuthAdapter($this->authAdapterMock); try { $provider->authProcess(); } catch (RedirectException $red) { } catch (\Exception $e) { } $message = Messages::pop(); $this->assertEquals("First you need to be linked to Facebook", $message->text); }
/** * Setup an adapter for a given provider */ public static function setup($providerId, $params = NULL) { Hybrid_Logger::debug("Enter Hybrid_Auth::setup( {$providerId} )", $params); if (!$params) { $params = Hybrid_Auth::storage()->get("hauth_session.{$providerId}.id_provider_params"); Hybrid_Logger::debug("Hybrid_Auth::setup( {$providerId} ), no params given. Trying to get the sotred for this provider.", $params); } if (!$params) { $params = array(); Hybrid_Logger::info("Hybrid_Auth::setup( {$providerId} ), no stored params found for this provider. Initialize a new one for new session"); } if (!isset($params["hauth_return_to"])) { $params["hauth_return_to"] = Hybrid_Auth::getCurrentUrl(); } Hybrid_Logger::debug("Hybrid_Auth::setup( {$providerId} ). HybridAuth Callback URL set to: ", $params["hauth_return_to"]); # instantiate a new IDProvider Adapter $provider = new Hybrid_Provider_Adapter(); $provider->factory($providerId, $params); return $provider; }
/** * Setup an adapter for a given provider */ public static function setup($providerId, $params = NULL) { if (!$params) { $params = Hybrid_Auth::storage()->get("hauth_session.{$providerId}.id_provider_params"); } if (!$params) { $params = array(); } if (is_array($params) && !isset($params["hauth_return_to"])) { $params["hauth_return_to"] = Hybrid_Auth::getCurrentUrl(); } # instantiate a new IDProvider Adapter $provider = new Hybrid_Provider_Adapter(); $provider->factory($providerId, $params); return $provider; }
/** * processGithub * * @param \Hybrid_Provider_Adapter $adapter * @param Credential $credential * * @return Credential */ protected function processGitHub(\Hybrid_Provider_Adapter $adapter, Credential $credential) { $userProfile = $adapter->getUserProfile(); $loginName = $this->warder->getLoginName(); // Generate a temp username that usr can edit it later. if ($loginName != 'email') { $username = strtolower(str_replace(' ', '', $userProfile->displayName)) . '-' . $userProfile->identifier; $credential->{$loginName} = $username; } $credential->email = $userProfile->email; $credential->name = $userProfile->displayName; $credential->_loginName = 'email'; return $credential; }
/** * @return \Hybrid_User_Profile */ public function getProfile() { return $this->authAdapter->getUserProfile(); }
/** * Things to do AFTER connected. * Extend this class then overwrite this method to implement your own logic * * @param Request $request * @param \Hybrid_Provider_Adapter $adapter */ protected function postProcess(Request $request, \Hybrid_Provider_Adapter $adapter) { $user = $adapter->getUserProfile(); print_r($user); die; }