Example #1
0
 /**
  * Handle a successful account authentication.
  *
  * @param AccessToken $accessToken
  *
  * @throws Ex\MissingAccountException
  * @throws Ex\InvalidAuthorisationRequestException
  */
 protected function handleAccountTransition(AccessToken $accessToken)
 {
     $providerName = $this->providerManager->getProviderName();
     $resourceOwner = $this->getResourceOwner($accessToken);
     $email = $resourceOwner->getEmail();
     if ((bool) $email === false) {
         // Redirect to registration
         $this->setDebugMessage(sprintf('No email address found for transitional %s provider ID %s', $providerName, $resourceOwner->getId()));
         throw new Ex\MissingAccountException(sprintf('Provider %s data for ID %s does not include an email address.', $providerName, $resourceOwner->getId()));
     }
     $guid = $this->session->getAuthorisation()->getGuid();
     $accountEntity = $this->records->getAccountByGuid($guid);
     if ($accountEntity === false) {
         $accountEntity = $this->records->getAccountByEmail($email);
     }
     if ($accountEntity === false) {
         $this->setDebugMessage(sprintf('No account found for transitional %s provider ID %s', $providerName, $resourceOwner->getId()));
         throw new Ex\MissingAccountException(sprintf('No account for %s provider ID %s during transition', $providerName, $resourceOwner->getId()));
     }
     $providerEntity = $this->session->getTransitionalProvider()->getProviderEntity();
     $providerEntity->setGuid($accountEntity->getGuid());
     $providerEntity->setLastupdate(Carbon::now());
     $this->records->saveProvider($providerEntity);
     $this->session->removeTransitionalProvider();
     $this->setSession($accessToken);
 }
Example #2
0
 /**
  * Create a 'remote' provider record from a session stored 'transitional' one.
  *
  * @param string $guid
  *
  * @return Storage\Entity\Provider
  */
 protected function convertTransitionalProviderToEntity($guid)
 {
     $provider = $this->session->getTransitionalProvider()->getProviderEntity();
     $provider->setGuid($guid);
     $provider->setLastupdate(Carbon::now());
     $this->records->saveProvider($provider);
     $this->session->removeTransitionalProvider();
     return $provider;
 }