2010-07-16 15 views
6

हाल ही में, मैंने ओपनआईडी को बेहतर ढंग से समझने के लिए अपना स्वयं का PHP ओपनआईडी उपभोक्ता वर्ग लिखना शुरू कर दिया है। एक गाइड के रूप में, मैं [लाइट ओपेनिड क्लास] [1] का संदर्भ दे रहा हूं। अधिकांश भाग के लिए, मैं कोड को समझता हूं और ओपनआईडी कैसे काम करता है। मेरे भ्रम आता है जब लेखक का discover समारोह को देख:ओपनआईडी डिस्कवरी विधियां - याडीस वीएस एचटीएमएल

function discover($url) 
{ 
    if(!$url) throw new ErrorException('No identity supplied.'); 
    # We save the original url in case of Yadis discovery failure. 
    # It can happen when we'll be lead to an XRDS document 
    # which does not have any OpenID2 services. 
    $originalUrl = $url; 

    # A flag to disable yadis discovery in case of failure in headers. 
    $yadis = true; 

    # We'll jump a maximum of 5 times, to avoid endless redirections. 
    for($i = 0; $i < 5; $i ++) { 
     if($yadis) { 
      $headers = explode("\n",$this->request($url, 'HEAD')); 

      $next = false; 
      foreach($headers as $header) { 
       if(preg_match('#X-XRDS-Location\s*:\s*(.*)#', $header, $m)) { 
        $url = $this->build_url(parse_url($url), parse_url(trim($m[1]))); 
        $next = true; 
       } 

       if(preg_match('#Content-Type\s*:\s*application/xrds\+xml#i', $header)) { 
        # Found an XRDS document, now let's find the server, and optionally delegate. 
        $content = $this->request($url, 'GET'); 

        # OpenID 2 
        # We ignore it for MyOpenID, as it breaks sreg if using OpenID 2.0 
        $ns = preg_quote('http://specs.openid.net/auth/2.0/'); 
        if (preg_match('#<Service.*?>(.*)<Type>\s*'.$ns.'(.*?)\s*</Type>(.*)</Service>#s', $content, $m) 
         && !preg_match('/myopenid\.com/i', $this->identity)) { 
         $content = $m[1] . $m[3]; 
         if($m[2] == 'server') $this->identifier_select = true; 

         $content = preg_match('#<URI>(.*)</URI>#', $content, $server); 
         $content = preg_match('#<LocalID>(.*)</LocalID>#', $content, $delegate); 
         if(empty($server)) { 
          return false; 
         } 
         # Does the server advertise support for either AX or SREG? 
         $this->ax = preg_match('#<Type>http://openid.net/srv/ax/1.0</Type>#', $content); 
         $this->sreg = preg_match('#<Type>http://openid.net/sreg/1.0</Type>#', $content); 

         $server = $server[1]; 
         if(isset($delegate[1])) $this->identity = $delegate[1]; 
         $this->version = 2; 

         $this->server = $server; 
         return $server; 
        } 

        # OpenID 1.1 
        $ns = preg_quote('http://openid.net/signon/1.1'); 
        if(preg_match('#<Service.*?>(.*)<Type>\s*'.$ns.'\s*</Type>(.*)</Service>#s', $content, $m)) { 
         $content = $m[1] . $m[2]; 

         $content = preg_match('#<URI>(.*)</URI>#', $content, $server); 
         $content = preg_match('#<.*?Delegate>(.*)</.*?Delegate>#', $content, $delegate); 
         if(empty($server)) { 
          return false; 
         } 
         # AX can be used only with OpenID 2.0, so checking only SREG 
         $this->sreg = preg_match('#<Type>http://openid.net/sreg/1.0</Type>#', $content); 

         $server = $server[1]; 
         if(isset($delegate[1])) $this->identity = $delegate[1]; 
         $this->version = 1; 

         $this->server = $server; 
         return $server; 
        } 

        $next = true; 
        $yadis = false; 
        $url = $originalUrl; 
        $content = null; 
        break; 
       } 
      } 
      if($next) continue; 

      # There are no relevant information in headers, so we search the body. 
      $content = $this->request($url, 'GET'); 
      if($location = $this->htmlTag($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'value')) { 
       $url = $this->build_url(parse_url($url), parse_url($location)); 
       continue; 
      } 
     } 

     if(!$content) $content = $this->request($url, 'GET'); 

     # At this point, the YADIS Discovery has failed, so we'll switch 
     # to openid2 HTML discovery, then fallback to openid 1.1 discovery. 
     $server = $this->htmlTag($content, 'link', 'rel', 'openid2.provider', 'href'); 
     $delegate = $this->htmlTag($content, 'link', 'rel', 'openid2.local_id', 'href'); 
     $this->version = 2; 

     # Another hack for myopenid.com... 
     if(preg_match('/myopenid\.com/i', $server)) { 
      $server = null; 
     } 

     if(!$server) { 
      # The same with openid 1.1 
      $server = $this->htmlTag($content, 'link', 'rel', 'openid.server', 'href'); 
      $delegate = $this->htmlTag($content, 'link', 'rel', 'openid.delegate', 'href'); 
      $this->version = 1; 
     } 

     if($server) { 
      # We found an OpenID2 OP Endpoint 
      if($delegate) { 
       # We have also found an OP-Local ID. 
       $this->identity = $delegate; 
      } 
      $this->server = $server; 
      return $server; 
     } 

     throw new ErrorException('No servers found!'); 
    } 
    throw new ErrorException('Endless redirection!'); 
} 


    [1]: http://gitorious.org/lightopenid 

ठीक है, यहाँ तर्क के रूप में मैं इसे समझ (मूल रूप से) है: $url आप एक वैध XRDS फ़ाइल भेजता है

  1. चेक देखने के लिए कि फिर आप ओपनआईडी प्रदाता के एंडपॉइंट को समझने के लिए पार्स करते हैं।
    • मेरी समझ से, इसे याडीस प्रमाणीकरण विधि कहा जाता है।
  2. यदि कोई XRDS फ़ाइल पाया जाता है, एक HTML < लिंक > टैग कि endpoint का url शामिल के लिए प्रतिक्रिया के शरीर की जाँच करें।

क्या। । ओह।

मेरा मतलब गंभीरता से है? अनिवार्य रूप से प्रतिक्रिया प्रतिक्रिया स्क्रैप करें और आशा है कि आपको उचित विशेषता मान के साथ एक लिंक मिलेगा?

अब, मुझे गलत मत समझो, यह वर्ग एक आकर्षण की तरह काम करता है और यह कमाल है। मैं एंडपॉइंट खोजने के लिए उपयोग की जाने वाली दो अलग-अलग विधियों को तोड़ने में असफल रहा हूं: एक्सआरडीएस (याडीस) और एचटीएमएल।

मेरे प्रश्न

  1. उन केवल दो खोज प्रक्रिया में प्रयुक्त विधियों हैं?
  2. क्या केवल ओपनआईडी के संस्करण 1.1 में और दूसरा संस्करण 2 में उपयोग किया जाता है?
  3. क्या दोनों विधियों का समर्थन करना महत्वपूर्ण है?
  4. जिस साइट पर मैंने HTML विधि का सामना किया है वह है याहू। क्या वे पागल हैं?

आपके समय के लोगों के लिए धन्यवाद। अगर मैं थोड़ा सा झटकेदार लग रहा हूं, तो मैं क्षमा चाहता हूं, लेकिन अंततः मुझे यह समझने लगा कि मैं एंडपॉइंट को खोजने के लिए क्या कदम उठा रहा था, मैं वास्तव में इस पद्धति पर डर गया था।

उत्तर

5

Specification आपका मित्र है।

लेकिन अपने सवाल का जवाब:

  1. हां। ओपनआईडी विनिर्देशों द्वारा परिभाषित केवल दो विधियां हैं (कम से कम, यूआरएल के लिए - एक्सआरआई के लिए तीसरी विधि है)।
  2. नहीं, दोनों प्रोटोकॉल के दोनों संस्करणों के साथ उपयोग किया जा सकता है। फ़ंक्शन को सावधानी से पढ़ें, और आप देखेंगे कि यह दोनों संस्करणों के लिए दोनों विधियों का समर्थन करता है।
  3. यदि आप अपनी लाइब्रेरी प्रत्येक प्रदाता और उपयोगकर्ता के साथ काम करना चाहते हैं, तो आप बेहतर काम करेंगे। कुछ उपयोगकर्ता HTML टैग्स को अपनी साइट पर पेस्ट करते हैं, इसलिए उनकी साइट का यूआरएल ओपनिड के रूप में उपयोग किया जा सकता है।
  4. कुछ प्रदाताओं ने एक ही समय में दोनों तरीकों का उपयोग किया है, उपभोक्ताओं के साथ संगतता को मापने के लिए, जो YADIS खोज को कार्यान्वित नहीं कर रहा है (जो ओपनआईडी 1.1 का हिस्सा नहीं है, लेकिन इसका उपयोग किया जा सकता है)। तो यह समझ में आता है।

और हाँ, एचटीएमएल खोज प्रतिक्रिया शरीर में <link> की खोज करने के बारे में है। यही कारण है कि इसे HTML खोज कहा जाता है।

+0

उत्कृष्ट जानकारी, बहुत उपयोगी स्पष्टीकरण। मेरे भ्रम/निराशा को हल करने के लिए समय निकालने के लिए धन्यवाद। +1 और बूट का जवाब। –

संबंधित मुद्दे