/**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     $credentials = $token->getCredentials();
     if (is_null($credentials)) {
         throw new AuthenticationException(OAuth2::HTTP_BAD_REQUEST, null, 'Empty credentials');
     }
     $client = $this->storage->getClient($credentials[0]);
     if (is_null($client)) {
         throw new AuthenticationException(OAuth2::ERROR_INVALID_CLIENT);
     }
     if ($this->storage->checkClientCredentials($client, $credentials[1]) === false) {
         throw new AuthenticationException(OAuth2::ERROR_INVALID_CLIENT);
     }
     $token->eraseCredentials();
     $newToken = new SharedSecretToken(array("ROLE_SHARED_SECRET", "ROLE_OAUTH_CLIENT"));
     $newToken->setClient($client);
     $newToken->setAuthenticated(true);
     return $newToken;
 }