- # 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);
- }
+ 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) {
+ # XXX: trick the constructor into thinking this is the only node
+ $bogus_nodes = array($node);
+ return new Auth_Yadis_XRDS($parser, $bogus_nodes);
+ }
+ }
+ return null;
+ }
+
+ function addServices($xrd, $types, &$omb)
+ {
+ foreach ($types as $type) {
+ $matches = omb_get_services($xrd, $type);
+ if ($matches) {
+ $omb[$type] = $matches[0];
+ } else {
+ # no match for type
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function requestToken($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(),
+ array('User-Agent: Laconica/' . LACONICA_VERSION));
+ if ($result->status != 200) {
+ return null;
+ }
+
+ parse_str($result->body, $return);
+
+ return array($return['oauth_token'], $return['oauth_token_secret']);
+ }
+
+ function requestAuthorization($user, $omb, $token, $secret)
+ {
+ $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', common_config('license', 'url'));
+
+ $profile = $user->getProfile();
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->serverError(_('User without matching profile'));
+ return;
+ }
+
+ if (!is_null($profile->fullname)) {
+ $req->set_parameter('omb_listenee_fullname', $profile->fullname);
+ }
+ if (!is_null($profile->homepage)) {
+ $req->set_parameter('omb_listenee_homepage', $profile->homepage);
+ }
+ if (!is_null($profile->bio)) {
+ $req->set_parameter('omb_listenee_bio', $profile->bio);
+ }
+ if (!is_null($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);
+ }