diff options
-rw-r--r-- | Auth/OpenID/Discover.php | 40 | ||||
-rw-r--r-- | Auth/OpenID/TrustRoot.php | 2 |
2 files changed, 39 insertions, 3 deletions
diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php index ac17927..34bdae5 100644 --- a/Auth/OpenID/Discover.php +++ b/Auth/OpenID/Discover.php @@ -28,8 +28,12 @@ function Auth_OpenID_getOpenIDTypeURIs() Auth_OpenID_TYPE_2_0, Auth_OpenID_TYPE_1_2, Auth_OpenID_TYPE_1_1, - Auth_OpenID_TYPE_1_0, - Auth_OpenID_RP_RETURN_TO_URL_TYPE); + Auth_OpenID_TYPE_1_0); +} + +function Auth_OpenID_getOpenIDConsumerTypeURIs() +{ + return array(Auth_OpenID_RP_RETURN_TO_URL_TYPE); } @@ -194,6 +198,25 @@ class Auth_OpenID_ServiceEndpoint { } /* + * Parse the given document as XRDS looking for OpenID consumer services. + * + * @return array of Auth_OpenID_ServiceEndpoint or null if the + * document cannot be parsed. + */ + function consumerFromXRDS($uri, $xrds_text) + { + $xrds =& Auth_Yadis_XRDS::parseXRDS($xrds_text); + + if ($xrds) { + $yadis_services = + $xrds->services(array('filter_MatchesAnyOpenIDConsumerType')); + return Auth_OpenID_makeOpenIDEndpoints($uri, $yadis_services); + } + + return null; + } + + /* * Parse the given document as XRDS looking for OpenID services. * * @return array of Auth_OpenID_ServiceEndpoint or null if the @@ -340,6 +363,19 @@ function filter_MatchesAnyOpenIDType(&$service) return false; } +function filter_MatchesAnyOpenIDConsumerType(&$service) +{ + $uris = $service->getTypes(); + + foreach ($uris as $uri) { + if (in_array($uri, Auth_OpenID_getOpenIDConsumerTypeURIs())) { + return true; + } + } + + return false; +} + function Auth_OpenID_bestMatchingService($service, $preferred_types) { // Return the index of the first matching type, or something diff --git a/Auth/OpenID/TrustRoot.php b/Auth/OpenID/TrustRoot.php index cf06aa2..2d9f294 100644 --- a/Auth/OpenID/TrustRoot.php +++ b/Auth/OpenID/TrustRoot.php @@ -401,7 +401,7 @@ function Auth_OpenID_getAllowedReturnURLs($relying_party_url, &$fetcher, $discover_function = array('Auth_Yadis_Yadis', 'discover'); } - $xrds_parse_cb = array('Auth_OpenID_ServiceEndpoint', 'fromXRDS'); + $xrds_parse_cb = array('Auth_OpenID_ServiceEndpoint', 'consumerFromXRDS'); list($rp_url_after_redirects, $endpoints) = Auth_Yadis_getServiceEndpoints($relying_party_url, $xrds_parse_cb, |