/**
  * 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;
 }
Ejemplo n.º 2
0
 public function testConstructWithApiKShouldSetCredentials()
 {
     $token = new ApiKeyToken('key');
     $this->assertSame('key', $token->getCredentials());
 }