Created
July 31, 2014 02:06
-
-
Save tad3j/77adc20138336013aaef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace RacApi\V1\Authentication; | |
use Zend\Authentication\AuthenticationService; | |
use ZfcRbac\Exception; | |
use ZfcRbac\Identity\IdentityProviderInterface; | |
use Doctrine\ORM\EntityManager; | |
//use User\Entity\User; | |
class ZfcRbacAuthenticationIdentityProvider implements IdentityProviderInterface | |
{ | |
/** | |
* @var AuthenticationService | |
*/ | |
protected $authenticationService; | |
/** | |
* | |
* @var EntityManager | |
*/ | |
protected $em; | |
/** | |
* Constructor | |
* | |
* @param AuthenticationService $authenticationService | |
* @param EntityManager $em | |
*/ | |
public function __construct(AuthenticationService $authenticationService, EntityManager $em) | |
{ | |
$this->authenticationService = $authenticationService; | |
$this->em = $em; | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public function getIdentity() | |
{ | |
/* @var \ZF\MvcAuth\Identity\AuthenticatedIdentity $identity */ | |
$identity = $this->authenticationService->getIdentity(); | |
$oauthIdentity = $identity->getAuthenticationIdentity(); | |
if($oauthIdentity != null) | |
if(array_key_exists('user_id',$oauthIdentity)){ | |
$userId = $oauthIdentity['user_id']; | |
$user = $this->em->getRepository('User\Entity\User')->findOneBy(array('id'=>$userId)); | |
return $user; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment