public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return null;
     }
     // previously authenticated user
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         if (null !== $this->checker) {
             $this->checker->checkPostAuth($user);
         }
         $authenticated = TwitterAnywhereToken::createAuthenticated($user, $user->getRoles());
         $authenticated->setAttributes($token->getAttributes());
         return $authenticated;
     }
     if (!$this->isSignatureValid($token->getSignature(), sha1($token->getUser() . $this->consumerSecret))) {
         throw new AuthenticationException(sprintf('The presented signature was invalid.'));
     }
     if (null === $this->provider) {
         $authenticated = TwitterAnywhereToken::createAuthenticated($token->getUser(), array());
         $authenticated->setAttributes($token->getAttributes());
         return $authenticated;
     }
     try {
         $user = $this->provider->loadUserByUsername($token->getUser());
         $this->checker->checkPostAuth($user);
         $authenticated = TwitterAnywhereToken::createAuthenticated($user, $user->getRoles());
         $authenticated->setAttributes($token->getAttributes());
         return $authenticated;
     } catch (AuthenticationException $passthroughEx) {
         throw $passthroughEx;
     } catch (\Exception $ex) {
         throw new AuthenticationException($ex->getMessage(), null, 0, $ex);
     }
 }