public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        $apiKey = $token->getCredentials();

        $user = $this
            ->om
            ->getRepository($this->modelName)
            ->findOneBy(array($this->metadata->getPropertyName(ClassMetadata::API_KEY_PROPERTY) => (string) $apiKey));

        if (!$user) {
            $this->dispatcher->dispatch(Ma27ApiKeyAuthenticationEvents::FIREWALL_FAILURE, new OnFirewallFailureEvent());

            throw new AuthenticationException(
                sprintf('API key %s does not exist!', $apiKey)
            );
        }

        $token = new PreAuthenticatedToken(
            $user,
            $apiKey,
            $providerKey,
            $user->getRoles() ?: array()
        );

        $firewallEvent = new OnFirewallAuthenticationEvent($user);
        $firewallEvent->setToken($token);

        $this->dispatcher->dispatch(Ma27ApiKeyAuthenticationEvents::FIREWALL_LOGIN, $firewallEvent);

        return $token;
    }
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        $apiKey = $token->getCredentials();

        $user = $this
            ->om
            ->getRepository($this->modelName)
            ->findOneBy(array($this->metadata->getPropertyName(ClassMetadata::API_KEY_PROPERTY) => (string) $apiKey));

        if (!$user) {
            $this->dispatcher->dispatch(Ma27ApiKeyAuthenticationEvents::FIREWALL_FAILURE, new OnFirewallFailureEvent());

            throw new AuthenticationException(
                sprintf('API key %s does not exist!', $apiKey)
            );
        }

        $token = new PreAuthenticatedToken(
            $user,
            $apiKey,
            $providerKey,
            $user->getRoles() ?: array()
        );

        $firewallEvent = new OnFirewallAuthenticationEvent($user);
        $firewallEvent->setToken($token);

        $this->dispatcher->dispatch(Ma27ApiKeyAuthenticationEvents::FIREWALL_LOGIN, $firewallEvent);

        return $token;
    }
public function authenticateToken ( TokenInterface $ token , UserProviderInterface $ userProvider , $ providerKey ) { $ apiKey = $ token -> getCredentials ( ) ; $ user = $ this -> om -> getRepository ( $ this -> modelName ) -> findOneBy ( array ( $ this -> metadata -> getPropertyName ( ClassMetadata :: API_KEY_PROPERTY ) => ( string ) $ apiKey ) ) ; if ( ! $ user ) { $ this -> dispatcher -> dispatch ( Ma27ApiKeyAuthenticationEvents :: FIREWALL_FAILURE , new OnFirewallFailureEvent ( ) ) ; throw new AuthenticationException ( sprintf ( 'API key %s does not exist!' , $ apiKey ) ) ; } $ token = new PreAuthenticatedToken ( $ user , $ apiKey , $ providerKey , $ user -> getRoles ( ) ? : array ( ) ) ; $ firewallEvent = new OnFirewallAuthenticationEvent ( $ user ) ; $ firewallEvent -> setToken ( $ token ) ; $ this -> dispatcher -> dispatch ( Ma27ApiKeyAuthenticationEvents :: FIREWALL_LOGIN , $ firewallEvent ) ; return $ token ; }
Returns an authenticated token.

@param TokenInterface        $token
@param UserProviderInterface $userProvider
@param string                $providerKey

@throws AuthenticationException If the api key does not exist or is invalid
@throws \RuntimeException       If $userProvider is not an instance of AdvancedUserProviderInterface

@return PreAuthenticatedToken
Returns an authenticated token .