- $omb_service = $xrds->services(omb_service_filter(OMB_NAMESPACE));
-
- if (!$omb_service) {
- return NULL;
- }
-
- $xrd = $this->getXRD($omb_service, $xrds);
- $this->addServices($xrd, $omb_endpoints, $omb);
-
- # XXX: check that we got all the services we needed
-
- foreach (array_merge($omb_endpoints, $oauth_endpoints) as $type) {
- if (!array_key_exists($type, $omb)) {
- return NULL;
- }
- }
-
- if (!omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])) {
- return NULL;
- }
-
- return $omb;
- }
-
- function getXRD($main_service, $main_xrds) {
- $uri = omb_service_uri($main_service);
- if (strpos($uri, "#") !== 0) {
- # FIXME: more rigorous handling of external service definitions
- return NULL;
- }
- $id = substr($uri, 1);
- $nodes = $main_xrds->allXrdNodes;
- $parser = $main_xrds->parser;
- foreach ($nodes as $node) {
- $attrs = $parser->attributes($node);
- if (array_key_exists('xml:id', $attrs) &&
- $attrs['xml:id'] == $id) {
- return new Auth_Yadis_XRDS($parser, array($node));
- }
- }
- return NULL;
- }
-
- function addServices($xrd, $types, &$omb) {
- foreach ($types as $type) {
- $matches = $xrd->services(omb_service_filter($type));
- if ($matches) {
- $omb[$type] = $services[0];
- } else {
- # no match for type
- return false;
- }
- }
- return true;
- }
-
- function request_token($omb) {
- $con = omb_oauth_consumer();
-
- $url = omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]);
-
- # XXX: Is this the right thing to do? Strip off GET params and make them
- # POST params? Seems wrong to me.
-
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
-
- $req = OAuthRequest::from_consumer_and_token($con, NULL, "POST", $url, $params);
-
- $listener = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]);
-
- if (!$listener) {
- return NULL;
- }
-
- $req->set_parameter('omb_listener', $listener);
- $req->set_parameter('omb_version', OMB_VERSION_01);
-
- # XXX: test to see if endpoint accepts this signature method
-
- $req->sign_request(omb_hmac_sha1(), $con, NULL);
-
- # We re-use this tool's fetcher, since it's pretty good
-
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
- $result = $fetcher->post($req->get_normalized_http_url(),
- $req->to_postdata());
-
- if ($result->status != 200) {
- return NULL;
- }
-
- parse_str($result->body, $return);
-
- return array($return['oauth_token'], $return['oauth_token_secret']);
- }
-
- function request_authorization($user, $omb, $token, $secret) {
- global $config; # for license URL
-
- $con = omb_oauth_consumer();
- $tok = new OAuthToken($token, $secret);
-
- $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]);
-
- # XXX: Is this the right thing to do? Strip off GET params and make them
- # POST params? Seems wrong to me.
-
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
-
- $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params);
-
- # We send over a ton of information. This lets the other
- # server store info about our user, and it lets the current
- # user decide if they really want to authorize the subscription.
-
- $req->set_parameter('omb_version', OMB_VERSION_01);
- $req->set_parameter('omb_listener', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]));
- $req->set_parameter('omb_listenee', $user->uri);
- $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname));
- $req->set_parameter('omb_listenee_nickname', $user->nickname);
- $req->set_parameter('omb_listenee_license', $config['license']['url']);
- $profile = $user->getProfile();
- if ($profile->fullname) {
- $req->set_parameter('omb_listenee_fullname', $profile->fullname);
- }
- if ($profile->homepage) {
- $req->set_parameter('omb_listenee_homepage', $profile->homepage);
- }
- if ($profile->bio) {
- $req->set_parameter('omb_listenee_bio', $profile->bio);
- }
- if ($profile->location) {
- $req->set_parameter('omb_listenee_location', $profile->location);
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- if ($avatar) {
- $req->set_parameter('omb_listenee_avatar', $avatar->url);
- }
-
- $nonce = $this->make_nonce();
-
- $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe',
- array('nonce' => $nonce)));
-
- # XXX: test to see if endpoint accepts this signature method
-
- $req->sign_request(omb_hmac_sha1(), $con, $tok);
-
- # store all our info here