function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] == 'POST') { /* Use a session token for CSRF protection. */ $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $srv = $this->getStoredParams(); // TRANS: Client error displayed when the session token does not match or is not given. $this->showForm($srv->getRemoteUser(), _('There was a problem ' . 'with your session token. Try again, ' . 'please.')); return; } /* We've shown the form, now post user's choice. */ $this->sendAuthorization(); } else { if (!common_logged_in()) { /* Go log in, and then come back. */ common_set_returnto($_SERVER['REQUEST_URI']); common_redirect(common_local_url('login')); return; } $user = common_current_user(); $profile = $user->getProfile(); if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.')); return; } /* TODO: If no token is passed the user should get a prompt to enter it according to OAuth Core 1.0. */ try { $this->validateOmb(); $srv = new OMB_Service_Provider(profile_to_omb_profile($user->uri, $profile), omb_oauth_datastore()); $remote_user = $srv->handleUserAuth(); } catch (Exception $e) { $this->clearParams(); $this->clientError($e->getMessage()); return; } $this->storeParams($srv); $this->showForm($remote_user); } }
function notice_to_omb_notice($notice) { /* Create an OMB_Notice for $notice. */ $user = User::staticGet('id', $notice->profile_id); if (!$user) { return null; } $profile = $user->getProfile(); $omb_notice = new OMB_Notice(profile_to_omb_profile($user->uri, $profile), $notice->uri, $notice->content); $omb_notice->setURL(common_local_url('shownotice', array('notice' => $notice->id))); $omb_notice->setLicenseURL(common_config('license', 'url')); return $omb_notice; }
/** * Get profile by identifying URI * * Returns an OMB_Profile object representing the OMB profile identified by * $identifier_uri. * Returns null if there is no such OMB profile. * Throws exceptions in case of other error. * * @param string $identifier_uri The OMB identifier URI specifying the * requested profile * * @access public * * @return OMB_Profile The corresponding profile **/ public function getProfile($identifier_uri) { /* getProfile is only used for remote profiles by libomb. @TODO: Make it work with local ones anyway. */ $remote = Remote_profile::staticGet('uri', $identifier_uri); if (!$remote) { throw new Exception('No such remote profile'); } $profile = Profile::staticGet('id', $remote->id); if (!$profile) { throw new Exception('No profile for remote user'); } require_once INSTALLDIR . '/lib/omb.php'; return profile_to_omb_profile($identifier_uri, $profile); }
function remoteSubscription() { if (!$this->nickname) { $this->showForm(_('No such user.')); return; } $user = User::staticGet('nickname', $this->nickname); $this->profile_url = $this->trimmed('profile_url'); if (!$this->profile_url) { $this->showForm(_('No such user.')); return; } if (!common_valid_http_url($this->profile_url)) { $this->showForm(_('Invalid profile URL (bad format)')); return; } try { $service = new OMB_Service_Consumer($this->profile_url, common_root_url(), omb_oauth_datastore()); } catch (OMB_InvalidYadisException $e) { $this->showForm(_('Not a valid profile URL (no YADIS document or ' . 'invalid XRDS defined).')); return; } if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) == common_local_url('requesttoken') || User::staticGet('uri', $service->getRemoteUserURI())) { $this->showForm(_('That’s a local profile! Login to subscribe.')); return; } try { $service->requestToken(); } catch (OMB_RemoteServiceException $e) { $this->showForm(_('Couldn’t get a request token.')); return; } /* Create an OMB_Profile from $user. */ $profile = $user->getProfile(); if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); $this->serverError(_('User without matching profile.')); return; } $target_url = $service->requestAuthorization(profile_to_omb_profile($user->uri, $profile), common_local_url('finishremotesubscribe')); common_ensure_session(); $_SESSION['oauth_authorization_request'] = serialize($service); /* Redirect to the remote service for authorization. */ common_redirect($target_url, 303); }