public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $adapter = $this->getAdapter();
     $account = null;
     $response = null;
     $error = $request->getStr('error');
     if ($error) {
         $response = $controller->buildProviderErrorResponse($this, pht('The OAuth provider returned an error: %s', $error));
         return array($account, $response);
     }
     $this->verifyAuthCSRFCode($request, $request->getStr('state'));
     $code = $request->getStr('code');
     if (!strlen($code)) {
         $response = $controller->buildProviderErrorResponse($this, pht('The OAuth provider did not return a "code" parameter in its ' . 'response.'));
         return array($account, $response);
     }
     $adapter->setCode($code);
     // NOTE: As a side effect, this will cause the OAuth adapter to request
     // an access token.
     try {
         $account_id = $adapter->getAccountID();
     } catch (Exception $ex) {
         // TODO: Handle this in a more user-friendly way.
         throw $ex;
     }
     if (!strlen($account_id)) {
         $response = $controller->buildProviderErrorResponse($this, pht('The OAuth provider failed to retrieve an account ID.'));
         return array($account, $response);
     }
     return array($this->loadOrCreateAccount($account_id), $response);
 }
 public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $adapter = $this->getAdapter();
     $account = null;
     $response = null;
     if ($request->isHTTPPost()) {
         // Add a CSRF code to the callback URI, which we'll verify when
         // performing the login.
         $client_code = $this->getAuthCSRFCode($request);
         $callback_uri = $adapter->getCallbackURI();
         $callback_uri = $callback_uri . $client_code . '/';
         $adapter->setCallbackURI($callback_uri);
         $uri = $adapter->getClientRedirectURI();
         $this->saveHandshakeTokenSecret($client_code, $adapter->getTokenSecret());
         $response = id(new AphrontRedirectResponse())->setIsExternal(true)->setURI($uri);
         return array($account, $response);
     }
     $denied = $request->getStr('denied');
     if (strlen($denied)) {
         // Twitter indicates that the user cancelled the login attempt by
         // returning "denied" as a parameter.
         throw new PhutilAuthUserAbortedException();
     }
     // NOTE: You can get here via GET, this should probably be a bit more
     // user friendly.
     $this->verifyAuthCSRFCode($request, $controller->getExtraURIData());
     $token = $request->getStr('oauth_token');
     $verifier = $request->getStr('oauth_verifier');
     if (!$token) {
         throw new Exception("Expected 'oauth_token' in request!");
     }
     if (!$verifier) {
         throw new Exception("Expected 'oauth_verifier' in request!");
     }
     $adapter->setToken($token);
     $adapter->setVerifier($verifier);
     $client_code = $this->getAuthCSRFCode($request);
     $token_secret = $this->loadHandshakeTokenSecret($client_code);
     $adapter->setTokenSecret($token_secret);
     // NOTE: As a side effect, this will cause the OAuth adapter to request
     // an access token.
     try {
         $account_id = $adapter->getAccountID();
     } catch (Exception $ex) {
         // TODO: Handle this in a more user-friendly way.
         throw $ex;
     }
     if (!strlen($account_id)) {
         $response = $controller->buildProviderErrorResponse($this, pht('The OAuth provider failed to retrieve an account ID.'));
         return array($account, $response);
     }
     return array($this->loadOrCreateAccount($account_id), $response);
 }
 public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $adapter = $this->getAdapter();
     $account = null;
     $response = null;
     try {
         $account_id = $adapter->getAccountID();
     } catch (Exception $ex) {
         // TODO: Handle this in a more user-friendly way.
         throw $ex;
     }
     if (!strlen($account_id)) {
         $response = $controller->buildProviderErrorResponse($this, pht('The web server failed to provide an account ID.'));
         return array($account, $response);
     }
     return array($this->loadOrCreateAccount($account_id), $response);
 }