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); } }
protected function attemptAuthentication(Request $request) { if ($this->useTwitterAnywhere) { if (null === ($identity = $request->cookies->get('twitter_anywhere_identity'))) { throw new AuthenticationException(sprintf('Identity cookie "twitter_anywhere_identity" was not sent.')); } if (false === ($pos = strpos($identity, ':'))) { throw new AuthenticationException(sprintf('The submitted identity "%s" is invalid.', $identity)); } return $this->authenticationManager->authenticate(TwitterAnywhereToken::createUnauthenticated(substr($identity, 0, $pos), substr($identity, $pos + 1))); } return $this->authenticationManager->authenticate(new TwitterUserToken($request->query->get('oauth_token'), $request->query->get('oauth_verifier'))); }