コード例 #1
0
 /**
  * Finish authorization
  *
  * Finish the subscription process by converting the received and authorized
  * request token into an access token. After that, the subscriber’s profile
  * and the subscription are stored in the database.
  * Expects an OAuthRequest in query parameters.
  * Throws exceptions on failure.
  *
  * @access public
  */
 public function finishAuthorization()
 {
     OMB_Helper::removeMagicQuotesFromRequest();
     $req = OAuthRequest::from_request();
     if ($req->get_parameter('oauth_token') != $this->token->key) {
         /* That’s not the token I wanted to get authorized. */
         throw new OAuthException('The authorized token does not equal ' . 'the submitted token.');
     }
     if ($req->get_parameter('omb_version') != OMB_VERSION) {
         throw new OMB_RemoteServiceException('The remote service uses an ' . 'unsupported OMB version');
     }
     /* Construct the profile to validate it. */
     /* Fix OMB bug. Listener URI is not passed. */
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $params = $_POST;
     } else {
         $params = $_GET;
     }
     $params['omb_listener'] = $this->listener_uri;
     $listener = OMB_Profile::fromParameters($params, 'omb_listener');
     /* Ask the remote service to convert the authorized request token into
        an access token. */
     $result = $this->performAction(OAUTH_ENDPOINT_ACCESS, array());
     if ($result->status != 200) {
         throw new OAuthException('Could not get access token');
     }
     parse_str($result->body, $return);
     if (!isset($return['oauth_token']) || !isset($return['oauth_token_secret'])) {
         throw new OAuthException('Could not get access token');
     }
     $this->setToken($return['oauth_token'], $return['oauth_token_secret']);
     /* Subscription is finished and valid. Now store the new subscriber and
        the subscription in the database. */
     $this->datastore->saveProfile($listener);
     $this->datastore->saveSubscription($this->listener_uri, $this->listenee_uri, $this->token);
 }
コード例 #2
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);
 }