Skip to content

Commit

Permalink
Handling exception from HybriAuth
Browse files Browse the repository at this point in the history
- It seems HybridAuth throws an exception during instantiation if the
  user cancelled login from a provider (at least for Facebook).

Resolves #168
  • Loading branch information
SocalNick committed Sep 8, 2014
1 parent 209853a commit 51d91d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ScnSocialAuth/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public function providerAuthenticateAction()
return $this->notFoundAction();
}

if (!$this->hybridAuth) {
// This is likely user that cancelled login...
return $this->redirect()->toRoute('zfcuser/login');
}

// For provider authentication, change the auth adapter in the ZfcUser Controller Plugin
$this->zfcUserAuthentication()->setAuthAdapter($this->getServiceLocator()->get('ScnSocialAuth-AuthenticationAdapterChain'));

Expand Down
9 changes: 7 additions & 2 deletions src/ScnSocialAuth/Service/UserControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ class UserControllerFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $controllerManager)
{
$mapper = $controllerManager->getServiceLocator()->get('ScnSocialAuth-UserProviderMapper');
$hybridAuth = $controllerManager->getServiceLocator()->get('HybridAuth');
$moduleOptions = $controllerManager->getServiceLocator()->get('ScnSocialAuth-ModuleOptions');
$redirectCallback = $controllerManager->getServiceLocator()->get('zfcuser_redirect_callback');

$controller = new UserController($redirectCallback);
$controller->setMapper($mapper);
$controller->setHybridAuth($hybridAuth);
$controller->setOptions($moduleOptions);

try {
$hybridAuth = $controllerManager->getServiceLocator()->get('HybridAuth');
$controller->setHybridAuth($hybridAuth);
} catch (\Zend\ServiceManager\Exception\ServiceNotCreatedException $e) {
// This is likely the user cancelling login...
}

return $controller;
}
}

0 comments on commit 51d91d8

Please sign in to comment.