/**
  * Create exception from Yadis response
  *
  * Creates an exception from a passed yadis result.
  *
  * @param string                  $request_uri The target URI for the failed
  *                                             request
  * @param Auth_Yadis_HTTPResponse $result      The result of the failed
  *                                             request
  *
  * @return OMB_RemoteServiceException A new exception
  */
 public static function fromYadis($request_uri, $result)
 {
     if ($result->status == 200) {
         $err = 'Got wrong response ' . $result->body;
     } else {
         $err = 'Got error code ' . $result->status . ' with response ' . $result->body;
     }
     return OMB_RemoteServiceException::forRequest($request_uri, $err);
 }
Exemplo n.º 2
0
 /**
  * Perform an OMB action
  *
  * Executes an OMB action – as of OMB 0.1, it’s one of updateProfile and
  * postNotice.
  *
  * @param string $action_uri   The URI specifying the target service
  * @param array  $params       Additional parameters for the service call
  * @param string $listenee_uri The URI identifying the local user for whom
  *                             the action is performed
  *
  * @access protected
  */
 protected function performOMBAction($action_uri, $params, $listenee_uri)
 {
     $result = $this->performAction($action_uri, $params);
     if ($result->status == 403) {
         /* The remote user unsubscribed us. */
         $this->datastore->deleteSubscription($this->listener_uri, $listenee_uri);
     } else {
         if ($result->status != 200 || strpos($result->body, 'omb_version=' . OMB_VERSION) === false) {
             /* The server signaled an error or sent an incorrect response. */
             throw OMB_RemoteServiceException::fromYadis($action_uri, $result);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Handle an OMB request
  *
  * Performs common OMB request handling.
  *
  * @param string $uri The URI defining the OMB endpoint being served
  *
  * @access protected
  *
  * @return array(OAuthRequest, OMB_Profile)
  */
 protected function handleOMBRequest($uri)
 {
     OMB_Helper::removeMagicQuotesFromRequest();
     $req = OAuthRequest::from_request('POST');
     $listenee = $req->get_parameter('omb_listenee');
     try {
         list($consumer, $token) = $this->getOAuthServer()->verify_request($req);
     } catch (OAuthException $e) {
         header('HTTP/1.1 403 Forbidden');
         throw OMB_RemoteServiceException::forRequest($uri, 'Revoked accesstoken for ' . $listenee);
     }
     $version = $req->get_parameter('omb_version');
     if ($version !== OMB_VERSION) {
         header('HTTP/1.1 400 Bad Request');
         throw OMB_RemoteServiceException::forRequest($uri, 'Wrong OMB version ' . $version);
     }
     $profile = $this->datastore->getProfile($listenee);
     if (is_null($profile)) {
         header('HTTP/1.1 400 Bad Request');
         throw OMB_RemoteServiceException::forRequest($uri, 'Unknown remote profile ' . $listenee);
     }
     $subscribers = $this->datastore->getSubscriptions($listenee);
     if (count($subscribers) === 0) {
         header('HTTP/1.1 403 Forbidden');
         throw OMB_RemoteServiceException::forRequest($uri, 'No subscriber for ' . $listenee);
     }
     return array($req, $profile);
 }