/**
  * Authenticate the user based on an API key
  *
  * @param TokenInterface $token
  */
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByApiKey($this->encoder->encodePassword($token->getCredentials()));
     if (!$user || !$user instanceof UserInterface) {
         throw new AuthenticationException('Bad credentials');
     }
     $token = new ApiKeyToken($token->getCredentials(), $user->getRoles());
     $token->setUser($user);
     return $token;
 }
示例#2
0
 /**
  * @expectedException \LogicException
  */
 public function testAuthenticateAfterInstantiationShouldThrowException()
 {
     $token = new ApiKeyToken('key');
     $token->setAuthenticated(true);
 }