ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Discover.php File Reference

Go to the source code of this file.

Data Structures

class  Auth_OpenID_ServiceEndpoint
 Object representing an OpenID service endpoint. More...
 

Functions

 Auth_OpenID_getOpenIDTypeURIs ()
 
 Auth_OpenID_getOpenIDConsumerTypeURIs ()
 
 Auth_OpenID_getOpenIDTypeName ($type_uri)
 
 Auth_OpenID_findOPLocalIdentifier ($service, $type_uris)
 
 filter_MatchesAnyOpenIDType ($service)
 
 filter_MatchesAnyOpenIDConsumerType (&$service)
 
 Auth_OpenID_bestMatchingService ($service, $preferred_types)
 
 Auth_OpenID_arrangeByType ($service_list, $preferred_types)
 
 Auth_OpenID_getOPOrUserServices ($openid_services)
 
 Auth_OpenID_makeOpenIDEndpoints ($uri, $yadis_services)
 
 Auth_OpenID_discoverWithYadis ($uri, $fetcher, $endpoint_filter='Auth_OpenID_getOPOrUserServices', $discover_function=null)
 
 Auth_OpenID_discoverURI ($uri, $fetcher)
 
 Auth_OpenID_discoverWithoutYadis ($uri, $fetcher)
 
 Auth_OpenID_discoverXRI ($iname, $fetcher)
 
 Auth_OpenID_discover ($uri, $fetcher)
 

Variables

const Auth_OpenID_XMLNS_1_0 'http://openid.net/xmlns/1.0'
 The OpenID and Yadis discovery implementation for OpenID 1.2. More...
 
const Auth_OpenID_TYPE_1_2 'http://openid.net/signon/1.2'
 
const Auth_OpenID_TYPE_1_1 'http://openid.net/signon/1.1'
 
const Auth_OpenID_TYPE_1_0 'http://openid.net/signon/1.0'
 
const Auth_OpenID_TYPE_2_0_IDP 'http://specs.openid.net/auth/2.0/server'
 
const Auth_OpenID_TYPE_2_0 'http://specs.openid.net/auth/2.0/signon'
 
const Auth_OpenID_RP_RETURN_TO_URL_TYPE 'http://specs.openid.net/auth/2.0/return_to'
 

Function Documentation

◆ Auth_OpenID_arrangeByType()

Auth_OpenID_arrangeByType (   $service_list,
  $preferred_types 
)

Definition at line 397 of file Discover.php.

399{
400 // Rearrange service_list in a new list so services are ordered by
401 // types listed in preferred_types. Return the new list.
402
403 // Build a list with the service elements in tuples whose
404 // comparison will prefer the one with the best matching service
405 $prio_services = array();
406 foreach ($service_list as $index => $service) {
407 $prio_services[] = array(Auth_OpenID_bestMatchingService($service,
408 $preferred_types),
409 $index, $service);
410 }
411
412 sort($prio_services);
413
414 // Now that the services are sorted by priority, remove the sort
415 // keys from the list.
416 foreach ($prio_services as $index => $s) {
417 $prio_services[$index] = $prio_services[$index][2];
418 }
419
420 return $prio_services;
Auth_OpenID_bestMatchingService($service, $preferred_types)
Definition: Discover.php:378

References Auth_OpenID_bestMatchingService().

Referenced by Auth_OpenID_getOPOrUserServices().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_bestMatchingService()

Auth_OpenID_bestMatchingService (   $service,
  $preferred_types 
)

Definition at line 378 of file Discover.php.

380{
381 // Return the index of the first matching type, or something
382 // higher if no type matches.
383 //
384 // This provides an ordering in which service elements that
385 // contain a type that comes earlier in the preferred types list
386 // come before service elements that come later. If a service
387 // element has more than one type, the most preferred one wins.
388
389 foreach ($preferred_types as $index => $typ) {
390 if (in_array($typ, $service->type_uris)) {
391 return $index;
392 }
393 }
394
395 return count($preferred_types);

Referenced by Auth_OpenID_arrangeByType().

+ Here is the caller graph for this function:

◆ Auth_OpenID_discover()

Auth_OpenID_discover (   $uri,
  $fetcher 
)

Definition at line 573 of file Discover.php.

575{
576 // If the fetcher (i.e., PHP) doesn't support SSL, we can't do
577 // discovery on an HTTPS URL.
578 if ($fetcher->isHTTPS($uri) && !$fetcher->supportsSSL()) {
579 return array($uri, array());
580 }
581
582 if (Auth_Yadis_identifierScheme($uri) == 'XRI') {
583 $result = Auth_OpenID_discoverXRI($uri, $fetcher);
584 } else {
585 $result = Auth_OpenID_discoverURI($uri, $fetcher);
586 }
587
588 // If the fetcher doesn't support SSL, we can't interact with
589 // HTTPS server URLs; remove those endpoints from the list.
590 if (!$fetcher->supportsSSL()) {
591 $http_endpoints = array();
592 list($new_uri, $endpoints) = $result;
593
594 foreach ($endpoints as $e) {
595 if (!$fetcher->isHTTPS($e->server_url)) {
596 $http_endpoints[] = $e;
597 }
598 }
599
600 $result = array($new_uri, $http_endpoints);
601 }
602
603 return $result;
$result
Auth_OpenID_discoverXRI($iname, $fetcher)
Definition: Discover.php:550
Auth_OpenID_discoverURI($uri, $fetcher)
Definition: Discover.php:525
Auth_Yadis_identifierScheme($identifier)
Definition: XRI.php:43

References $result, Auth_OpenID_discoverURI(), Auth_OpenID_discoverXRI(), and Auth_Yadis_identifierScheme().

+ Here is the call graph for this function:

◆ Auth_OpenID_discoverURI()

Auth_OpenID_discoverURI (   $uri,
  $fetcher 
)

Definition at line 525 of file Discover.php.

527{
528 $uri = Auth_OpenID::normalizeUrl($uri);
529 return Auth_OpenID_discoverWithYadis($uri, $fetcher);
Auth_OpenID_discoverWithYadis($uri, $fetcher, $endpoint_filter='Auth_OpenID_getOPOrUserServices', $discover_function=null)
Definition: Discover.php:475
static normalizeUrl($url)
Given a URL, this "normalizes" it by adding a trailing slash and / or a leading http:// scheme where ...
Definition: OpenID.php:413

References Auth_OpenID_discoverWithYadis(), and Auth_OpenID\normalizeUrl().

Referenced by Auth_OpenID_discover().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_discoverWithoutYadis()

Auth_OpenID_discoverWithoutYadis (   $uri,
  $fetcher 
)

Definition at line 531 of file Discover.php.

533{
534 $http_resp = @$fetcher->get($uri);
535
536 if ($http_resp->status != 200 and $http_resp->status != 206) {
537 return array($uri, array());
538 }
539
540 $identity_url = $http_resp->final_url;
541
542 // Try to parse the response as HTML to get OpenID 1.0/1.1 <link
543 // rel="...">
544 $openid_services = Auth_OpenID_ServiceEndpoint::fromHTML(
545 $identity_url,
546 $http_resp->body);
547
548 return array($identity_url, $openid_services);
static fromHTML($uri, $html)
Definition: Discover.php:257

References Auth_OpenID_ServiceEndpoint\fromHTML().

Referenced by Auth_OpenID_discoverWithYadis().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_discoverWithYadis()

Auth_OpenID_discoverWithYadis (   $uri,
  $fetcher,
  $endpoint_filter = 'Auth_OpenID_getOPOrUserServices',
  $discover_function = null 
)

Definition at line 475 of file Discover.php.

479{
480 // Discover OpenID services for a URI. Tries Yadis and falls back
481 // on old-style <link rel='...'> discovery if Yadis fails.
482
483 // Might raise a yadis.discover.DiscoveryFailure if no document
484 // came back for that URI at all. I don't think falling back to
485 // OpenID 1.0 discovery on the same URL will help, so don't bother
486 // to catch it.
487 if ($discover_function === null) {
488 $discover_function = array('Auth_Yadis_Yadis', 'discover');
489 }
490
491 $openid_services = array();
492
493 $response = call_user_func_array($discover_function,
494 array($uri, $fetcher));
495
496 $yadis_url = $response->normalized_uri;
497 $yadis_services = array();
498
499 if ($response->isFailure() && !$response->isXRDS()) {
500 return array($uri, array());
501 }
502
503 $openid_services = Auth_OpenID_ServiceEndpoint::fromXRDS(
504 $yadis_url,
505 $response->response_text);
506
507 if (!$openid_services) {
508 if ($response->isXRDS()) {
510 $fetcher);
511 }
512
513 // Try to parse the response as HTML to get OpenID 1.0/1.1
514 // <link rel="...">
515 $openid_services = Auth_OpenID_ServiceEndpoint::fromHTML(
516 $yadis_url,
517 $response->response_text);
518 }
519
520 $openid_services = call_user_func_array($endpoint_filter,
521 array($openid_services));
522
523 return array($yadis_url, $openid_services);
Auth_OpenID_discoverWithoutYadis($uri, $fetcher)
Definition: Discover.php:531
static fromXRDS($uri, $xrds_text)
Definition: Discover.php:224

References Auth_OpenID_discoverWithoutYadis(), Auth_OpenID_ServiceEndpoint\fromHTML(), and Auth_OpenID_ServiceEndpoint\fromXRDS().

Referenced by Auth_OpenID_discoverURI().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_discoverXRI()

Auth_OpenID_discoverXRI (   $iname,
  $fetcher 
)

Definition at line 550 of file Discover.php.

552{
553 $resolver = new Auth_Yadis_ProxyResolver($fetcher);
554 list($canonicalID, $yadis_services) =
555 $resolver->query($iname,
557 array('filter_MatchesAnyOpenIDType'));
558
559 $openid_services = Auth_OpenID_makeOpenIDEndpoints($iname,
560 $yadis_services);
561
562 $openid_services = Auth_OpenID_getOPOrUserServices($openid_services);
563
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;
568 }
569
570 // FIXME: returned xri should probably be in some normal form
571 return array($iname, $openid_services);
Auth_OpenID_makeOpenIDEndpoints($uri, $yadis_services)
Definition: Discover.php:444
Auth_OpenID_getOPOrUserServices($openid_services)
Definition: Discover.php:429
Auth_OpenID_getOpenIDTypeURIs()
Definition: Discover.php:24
Code for using a proxy XRI resolver.
Definition: XRIRes.php:10

References Auth_OpenID_getOpenIDTypeURIs(), Auth_OpenID_getOPOrUserServices(), and Auth_OpenID_makeOpenIDEndpoints().

Referenced by Auth_OpenID_discover().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_findOPLocalIdentifier()

Auth_OpenID_findOPLocalIdentifier (   $service,
  $type_uris 
)

Definition at line 307 of file Discover.php.

309{
310 // Extract a openid:Delegate value from a Yadis Service element.
311 // If no delegate is found, returns null. Returns false on
312 // discovery failure (when multiple delegate/localID tags have
313 // different values).
314
315 $service->parser->registerNamespace('openid',
317
318 $service->parser->registerNamespace('xrd',
320
321 $parser = $service->parser;
322
323 $permitted_tags = array();
324
325 if (in_array(Auth_OpenID_TYPE_1_1, $type_uris) ||
326 in_array(Auth_OpenID_TYPE_1_0, $type_uris)) {
327 $permitted_tags[] = 'openid:Delegate';
328 }
329
330 if (in_array(Auth_OpenID_TYPE_2_0, $type_uris)) {
331 $permitted_tags[] = 'xrd:LocalID';
332 }
333
334 $local_id = null;
335
336 foreach ($permitted_tags as $tag_name) {
337 $tags = $service->getElements($tag_name);
338
339 foreach ($tags as $tag) {
340 $content = $parser->content($tag);
341
342 if ($local_id === null) {
343 $local_id = $content;
344 } else if ($local_id != $content) {
345 return false;
346 }
347 }
348 }
349
350 return $local_id;
const Auth_OpenID_TYPE_1_1
Definition: Discover.php:18
const Auth_OpenID_TYPE_1_0
Definition: Discover.php:19
const Auth_OpenID_TYPE_2_0
Definition: Discover.php:21
const Auth_OpenID_XMLNS_1_0
The OpenID and Yadis discovery implementation for OpenID 1.2.
Definition: Discover.php:14
const Auth_Yadis_XMLNS_XRD_2_0
XRD XML namespace.
Definition: XRDS.php:42

References Auth_OpenID_TYPE_1_0, Auth_OpenID_TYPE_1_1, Auth_OpenID_TYPE_2_0, Auth_OpenID_XMLNS_1_0, and Auth_Yadis_XMLNS_XRD_2_0.

Referenced by Auth_OpenID_ServiceEndpoint\parseService().

+ Here is the caller graph for this function:

◆ Auth_OpenID_getOpenIDConsumerTypeURIs()

Auth_OpenID_getOpenIDConsumerTypeURIs ( )

Definition at line 33 of file Discover.php.

35{
const Auth_OpenID_RP_RETURN_TO_URL_TYPE
Definition: Discover.php:22

References Auth_OpenID_RP_RETURN_TO_URL_TYPE.

Referenced by filter_MatchesAnyOpenIDConsumerType().

+ Here is the caller graph for this function:

◆ Auth_OpenID_getOpenIDTypeName()

Auth_OpenID_getOpenIDTypeName (   $type_uri)

Definition at line 43 of file Discover.php.

44 {
45 switch ($type_uri) {
47 return 'OpenID 2.0 IDP';
49 return 'OpenID 2.0';
51 return 'OpenID 1.2';
53 return 'OpenID 1.1';
55 return 'OpenID 1.0';
57 return 'OpenID relying party';
58 }
const Auth_OpenID_TYPE_1_2
Definition: Discover.php:17
const Auth_OpenID_TYPE_2_0_IDP
Definition: Discover.php:20

References Auth_OpenID_RP_RETURN_TO_URL_TYPE, Auth_OpenID_TYPE_1_0, Auth_OpenID_TYPE_1_1, Auth_OpenID_TYPE_1_2, Auth_OpenID_TYPE_2_0, and Auth_OpenID_TYPE_2_0_IDP.

◆ Auth_OpenID_getOpenIDTypeURIs()

◆ Auth_OpenID_getOPOrUserServices()

Auth_OpenID_getOPOrUserServices (   $openid_services)

Definition at line 429 of file Discover.php.

431{
432 $op_services = Auth_OpenID_arrangeByType($openid_services,
434
435 $openid_services = Auth_OpenID_arrangeByType($openid_services,
437
438 if ($op_services) {
439 return $op_services;
440 } else {
441 return $openid_services;
442 }
Auth_OpenID_arrangeByType($service_list, $preferred_types)
Definition: Discover.php:397

References Auth_OpenID_arrangeByType(), Auth_OpenID_getOpenIDTypeURIs(), and Auth_OpenID_TYPE_2_0_IDP.

Referenced by Auth_OpenID_discoverXRI().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_OpenID_makeOpenIDEndpoints()

Auth_OpenID_makeOpenIDEndpoints (   $uri,
  $yadis_services 
)

Definition at line 444 of file Discover.php.

446{
447 $s = array();
448
449 if (!$yadis_services) {
450 return $s;
451 }
452
453 foreach ($yadis_services as $service) {
454 $type_uris = $service->getTypes();
455 $uris = $service->getURIs();
456
457 // If any Type URIs match and there is an endpoint URI
458 // specified, then this is an OpenID endpoint
459 if ($type_uris &&
460 $uris) {
461 foreach ($uris as $service_uri) {
462 $openid_endpoint = new Auth_OpenID_ServiceEndpoint();
463 if ($openid_endpoint->parseService($uri,
464 $service_uri,
465 $type_uris,
466 $service)) {
467 $s[] = $openid_endpoint;
468 }
469 }
470 }
471 }
472
473 return $s;
Object representing an OpenID service endpoint.
Definition: Discover.php:63

Referenced by Auth_OpenID_discoverXRI(), Auth_OpenID_ServiceEndpoint\consumerFromXRDS(), and Auth_OpenID_ServiceEndpoint\fromXRDS().

+ Here is the caller graph for this function:

◆ filter_MatchesAnyOpenIDConsumerType()

filter_MatchesAnyOpenIDConsumerType ( $service)

Definition at line 365 of file Discover.php.

367{
368 $uris = $service->getTypes();
369
370 foreach ($uris as $uri) {
371 if (in_array($uri, Auth_OpenID_getOpenIDConsumerTypeURIs())) {
372 return true;
373 }
374 }
375
376 return false;
Auth_OpenID_getOpenIDConsumerTypeURIs()
Definition: Discover.php:33

References Auth_OpenID_getOpenIDConsumerTypeURIs().

+ Here is the call graph for this function:

◆ filter_MatchesAnyOpenIDType()

filter_MatchesAnyOpenIDType (   $service)

Definition at line 352 of file Discover.php.

354{
355 $uris = $service->getTypes();
356
357 foreach ($uris as $uri) {
358 if (in_array($uri, Auth_OpenID_getOpenIDTypeURIs())) {
359 return true;
360 }
361 }
362
363 return false;

References Auth_OpenID_getOpenIDTypeURIs().

+ Here is the call graph for this function:

Variable Documentation

◆ Auth_OpenID_RP_RETURN_TO_URL_TYPE

const Auth_OpenID_RP_RETURN_TO_URL_TYPE 'http://specs.openid.net/auth/2.0/return_to'

◆ Auth_OpenID_TYPE_1_0

const Auth_OpenID_TYPE_1_0 'http://openid.net/signon/1.0'

◆ Auth_OpenID_TYPE_1_1

◆ Auth_OpenID_TYPE_1_2

const Auth_OpenID_TYPE_1_2 'http://openid.net/signon/1.2'

Definition at line 17 of file Discover.php.

Referenced by Auth_OpenID_getOpenIDTypeName(), and Auth_OpenID_getOpenIDTypeURIs().

◆ Auth_OpenID_TYPE_2_0

◆ Auth_OpenID_TYPE_2_0_IDP

◆ Auth_OpenID_XMLNS_1_0

const Auth_OpenID_XMLNS_1_0 'http://openid.net/xmlns/1.0'

The OpenID and Yadis discovery implementation for OpenID 1.2.

Definition at line 14 of file Discover.php.

Referenced by Auth_OpenID_findOPLocalIdentifier().