7 require_once
"Auth/OpenID.php";
8 require_once
"Auth/OpenID/Parse.php";
9 require_once
"Auth/OpenID/Message.php";
10 require_once
"Auth/Yadis/XRIRes.php";
11 require_once
"Auth/Yadis/Yadis.php";
14 define(
'Auth_OpenID_XMLNS_1_0',
'http://openid.net/xmlns/1.0');
17 define(
'Auth_OpenID_TYPE_1_2',
'http://openid.net/signon/1.2');
18 define(
'Auth_OpenID_TYPE_1_1',
'http://openid.net/signon/1.1');
19 define(
'Auth_OpenID_TYPE_1_0',
'http://openid.net/signon/1.0');
20 define(
'Auth_OpenID_TYPE_2_0_IDP',
'http://specs.openid.net/auth/2.0/server');
21 define(
'Auth_OpenID_TYPE_2_0',
'http://specs.openid.net/auth/2.0/signon');
22 define(
'Auth_OpenID_RP_RETURN_TO_URL_TYPE',
23 'http://specs.openid.net/auth/2.0/return_to');
47 return 'OpenID 2.0 IDP';
57 return 'OpenID relying party';
67 $this->claimed_id = null;
68 $this->server_url = null;
69 $this->type_uris = array();
70 $this->local_id = null;
71 $this->canonicalID = null;
72 $this->used_yadis =
false;
73 $this->display_identifier = null;
78 if ($this->display_identifier) {
79 return $this->display_identifier;
81 if (! $this->claimed_id) {
82 return $this->claimed_id;
84 $parsed = parse_url($this->claimed_id);
85 $scheme = $parsed[
'scheme'];
86 $host = $parsed[
'host'];
87 $path = $parsed[
'path'];
88 if (array_key_exists(
'query', $parsed)) {
90 $no_frag =
"$scheme://$host$path?$query";
92 $no_frag =
"$scheme://$host$path";
99 return in_array($extension_uri, $this->type_uris);
126 foreach ($type_uris as $test_uri) {
128 $result[] = $test_uri;
138 return ((in_array($type_uri, $this->type_uris)) ||
158 $obj->server_url = $op_endpoint_url;
163 function parseService($yadis_url, $uri, $type_uris, $service_element)
168 $this->type_uris = $type_uris;
169 $this->server_url = $uri;
170 $this->used_yadis =
true;
173 $this->claimed_id = $yadis_url;
177 if ($this->local_id ===
false) {
189 if ($this->local_id === null && $this->canonicalID === null) {
190 return $this->claimed_id;
192 if ($this->local_id) {
193 return $this->local_id;
195 return $this->canonicalID;
212 $xrds->services(array(
'filter_MatchesAnyOpenIDConsumerType'));
225 static function fromXRDS($uri, $xrds_text)
231 $xrds->services(array(
'filter_MatchesAnyOpenIDType'));
247 if ($discoveryResult->isXRDS()) {
249 $discoveryResult->normalized_uri,
250 $discoveryResult->response_text);
253 $discoveryResult->normalized_uri,
254 $discoveryResult->response_text);
258 static function fromHTML($uri, $html)
260 $discovery_types = array(
262 'openid2.provider',
'openid2.local_id'),
264 'openid.server',
'openid.delegate')
269 foreach ($discovery_types as $triple) {
270 list($type_uri, $server_rel, $delegate_rel) = $triple;
275 if ($urls ===
false) {
279 list($delegate_url, $server_url) = $urls;
282 $service->claimed_id = $uri;
283 $service->local_id = $delegate_url;
284 $service->server_url = $server_url;
285 $service->type_uris = array($type_uri);
287 $services[] = $service;
297 $x->claimed_id = $this->claimed_id;
298 $x->server_url = $this->server_url;
299 $x->type_uris = $this->type_uris;
300 $x->local_id = $this->local_id;
301 $x->canonicalID = $this->canonicalID;
302 $x->used_yadis = $this->used_yadis;
315 $service->parser->registerNamespace(
'openid',
318 $service->parser->registerNamespace(
'xrd',
321 $parser = $service->parser;
323 $permitted_tags = array();
327 $permitted_tags[] =
'openid:Delegate';
331 $permitted_tags[] =
'xrd:LocalID';
336 foreach ($permitted_tags as $tag_name) {
337 $tags = $service->getElements($tag_name);
339 foreach ($tags as $tag) {
340 $content = $parser->content($tag);
342 if ($local_id === null) {
343 $local_id = $content;
344 }
else if ($local_id != $content) {
355 $uris = $service->getTypes();
357 foreach ($uris as $uri) {
368 $uris = $service->getTypes();
370 foreach ($uris as $uri) {
389 foreach ($preferred_types as $index => $typ) {
390 if (in_array($typ, $service->type_uris)) {
395 return count($preferred_types);
405 $prio_services = array();
406 foreach ($service_list as $index => $service) {
412 sort($prio_services);
416 foreach ($prio_services as $index => $s) {
417 $prio_services[$index] = $prio_services[$index][2];
420 return $prio_services;
441 return $openid_services;
449 if (!$yadis_services) {
453 foreach ($yadis_services as $service) {
454 $type_uris = $service->getTypes();
455 $uris = $service->getURIs();
461 foreach ($uris as $service_uri) {
463 if ($openid_endpoint->parseService($uri,
467 $s[] = $openid_endpoint;
477 $endpoint_filter=
'Auth_OpenID_getOPOrUserServices',
478 $discover_function=null)
487 if ($discover_function === null) {
488 $discover_function = array(
'Auth_Yadis_Yadis',
'discover');
491 $openid_services = array();
493 $response = call_user_func_array($discover_function,
494 array($uri, $fetcher));
496 $yadis_url = $response->normalized_uri;
497 $yadis_services = array();
499 if ($response->isFailure() && !$response->isXRDS()) {
500 return array($uri, array());
505 $response->response_text);
507 if (!$openid_services) {
508 if ($response->isXRDS()) {
517 $response->response_text);
520 $openid_services = call_user_func_array($endpoint_filter,
521 array($openid_services));
523 return array($yadis_url, $openid_services);
534 $http_resp = @$fetcher->get($uri);
536 if ($http_resp->status != 200 and $http_resp->status != 206) {
537 return array($uri, array());
540 $identity_url = $http_resp->final_url;
548 return array($identity_url, $openid_services);
554 list($canonicalID, $yadis_services) =
555 $resolver->query($iname,
557 array(
'filter_MatchesAnyOpenIDType'));
564 for ($i = 0; $i < count($openid_services); $i++) {
565 $openid_services[$i]->canonicalID = $canonicalID;
566 $openid_services[$i]->claimed_id = $canonicalID;
567 $openid_services[$i]->display_identifier = $iname;
571 return array($iname, $openid_services);
578 if ($fetcher->isHTTPS($uri) && !$fetcher->supportsSSL()) {
579 return array($uri, array());
590 if (!$fetcher->supportsSSL()) {
591 $http_endpoints = array();
592 list($new_uri, $endpoints) = $result;
594 foreach ($endpoints as $e) {
595 if (!$fetcher->isHTTPS($e->server_url)) {
596 $http_endpoints[] = $e;
600 $result = array($new_uri, $http_endpoints);