static public function getDataStore()
  {
    if (is_null(self::$dataStore))
    {
      self::$dataStore = new opOAuthDataStore();
    }

    return self::$dataStore;
  }
  static public function listenToPreActionEventOauthAccessToken(sfEvent $event)
  {
    $action = $event['actionInstance'];
    $request = sfContext::getInstance()->getRequest();

    if (!$request->hasParameter('x_auth_mode'))
    {
      return;
    }
    if ($request->getParameter('x_auth_mode') !== 'client_auth')
    {
      return;
    }

    $params = $request->getPostParameters();
    unset($params['x_auth_mode']);

    $formParams = array();
    foreach ($params as $key => $value)
    {
      if (strpos($key, 'x_auth_') === 0)
      {
         $formParams[mb_substr($key, 7)] = $value;
      }
    }

    $authForm = sfContext::getInstance()->getUser()->getAuthForm();
    $authForm->disableCSRFProtection();
    $authForm->bind($formParams);
    if (!$authForm->isValid())
    {
      return;
    }

    // request token
    $authRequest = OAuthRequest::from_request();
    $token = opXAuthPluginToolkit::getServer($action)->fetch_request_token($authRequest);
 
    // authorize token
    $information = opXAuthPluginToolkit::getTokenTable()->findByKeyString($token->key);
    $action->forward404Unless($information);

    $callback = $authRequest->get_parameter('oauth_callback');
    $information->setCallbackUrl($callback ? $callback : 'oob');
    $information->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
    $information->save();

    // accsess token
    $consumer = new OAuthConsumer($authRequest->get_parameter('oauth_consumer_key'));
    $token = opXAuthPluginToolkit::getDataStore()->new_access_token($token, $consumer);

    echo (string)$token;

    exit;
  }