Skip to content

Instantly share code, notes, and snippets.

@tad3j
Created July 31, 2014 02:06
Show Gist options
  • Save tad3j/77adc20138336013aaef to your computer and use it in GitHub Desktop.
Save tad3j/77adc20138336013aaef to your computer and use it in GitHub Desktop.
<?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