Example #1
0
 /**
  * Tests that getting and setting the local ID variable works properly
  *
  * @return void
  */
 public function testGetSetLocalID()
 {
     $testLocalID = 'foobar';
     $localID = $this->object->getLocalID();
     $this->assertNull($localID);
     $this->object->setLocalID($testLocalID);
     $localID = $this->object->getLocalID();
     $this->assertEquals($testLocalID, $localID);
 }
Example #2
0
 /**
  * Builds the service endpoint
  * 
  * @param array $results Array of items discovered via HTML
  * 
  * @return OpenID_ServiceEndpoints
  */
 protected function buildServiceEndpoint(array $results)
 {
     if (count($results['openid2.provider'])) {
         $version = OpenID::SERVICE_2_0_SIGNON;
         if (count($results['openid2.local_id'])) {
             $localID = $results['openid2.local_id'][0];
         }
         $endpointURIs = $results['openid2.provider'];
     } elseif (count($results['openid.server'])) {
         $version = OpenID::SERVICE_1_1_SIGNON;
         $endpointURIs = $results['openid.server'];
         if (count($results['openid.delegate'])) {
             $localID = $results['openid.delegate'][0];
         }
     } else {
         throw new OpenID_Discover_Exception('Discovered information does not conform to spec');
     }
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setVersion($version);
     $opEndpoint->setTypes(array($version));
     $opEndpoint->setURIs($endpointURIs);
     $opEndpoint->setSource(OpenID_Discover::TYPE_HTML);
     if (isset($localID)) {
         $opEndpoint->setLocalID($localID);
     }
     return new OpenID_ServiceEndpoints($this->identifier, $opEndpoint);
 }
Example #3
0
 /**
  * Performs YADIS discovery
  * 
  * @throws OpenID_Discover_Exception on error
  * @return OpenID_ServiceEndpoints
  */
 public function discover()
 {
     try {
         try {
             $discoveredServices = $this->getServicesYadis()->discover();
         } catch (Services_Yadis_Exception $e) {
             $message = 'Yadis protocol could not locate a valid XRD document';
             if ($e->getMessage() == $message) {
                 return false;
             }
             throw $e;
         }
         if (!$discoveredServices->valid()) {
             return false;
         }
         $service = new OpenID_ServiceEndpoints($this->getServicesYadis()->getYadisId());
         foreach ($discoveredServices as $discoveredService) {
             $types = $discoveredService->getTypes();
             if (array_key_exists($types[0], OpenID::$versionMap)) {
                 $version = $types[0];
                 $localID = null;
                 $localIDs = $discoveredService->getElements('xrd:LocalID');
                 if (!empty($localIDs[0])) {
                     $localID = $localIDs[0];
                 }
                 // Modify version if appropriate
                 if ($localID && $version == OpenID::SERVICE_2_0_SERVER) {
                     $version = OpenID::SERVICE_2_0_SIGNON;
                 }
                 $opEndpoint = new OpenID_ServiceEndpoint();
                 $opEndpoint->setVersion($types[0]);
                 // Choose OpenID 2.0 if it's available
                 if (count($types) > 1) {
                     foreach ($types as $type) {
                         if ($type == OpenID::SERVICE_2_0_SERVER || $type == OpenID::SERVICE_2_0_SIGNON) {
                             $opEndpoint->setVersion($type);
                             break;
                         }
                     }
                 }
                 $opEndpoint->setTypes($types);
                 $opEndpoint->setURIs($discoveredService->getUris());
                 $opEndpoint->setLocalID($localID);
                 $opEndpoint->setSource(OpenID_Discover::TYPE_YADIS);
                 $service->addService($opEndpoint);
             }
         }
         // Add in expires information
         $service->setExpiresHeader($this->getServicesYadis()->getHTTPResponse()->getHeader('Expires'));
         return $service;
     } catch (Services_Yadis_Exception $e) {
         // Add logging or observer?
         throw new OpenID_Discover_Exception($e->getMessage());
     }
     // Did the identifier even respond to the initial HTTP request?
     if ($this->yadis->getUserResponse() === false) {
         throw new OpenID_Discover_Exception('No response from identifier');
     }
 }
Example #4
0
 /**
  * testGetAuthorizeURLSignonLocalIDOneOne 
  * 
  * @return void
  */
 public function testGetAuthorizeURLSignonLocalIDOneOne()
 {
     $opEndpoint = new OpenID_ServiceEndpoint();
     $opEndpoint->setVersion(OpenID::SERVICE_1_1_SIGNON);
     $opEndpoint->setTypes(array(OpenID::SERVICE_1_1_SIGNON));
     $opEndpoint->setLocalID($this->identifier);
     $opEndpoint->setURIs(array($this->opURL));
     OpenID_Discover_Mock::$opEndpoint = $opEndpoint;
     $this->setObjects();
     $url = $this->authRequest->getAuthorizeURL();
     $split = preg_split('/\\?/', $url);
     $message = new OpenID_Message($split[1], OpenID_Message::FORMAT_HTTP);
     $this->assertNotSame($this->returnTo, $message->get('openid.return_to'));
     $this->assertSame($this->identifier, $message->get('openid.identity'));
     $this->assertSame(null, $message->get('openid.claimed_id'));
     $this->assertSame($this->opURL, $split[0]);
     // Mock nonce/store rather than have a new one created
     $store = new OpenID_Store_Mock();
     $nonce = new OpenID_Nonce($this->opURL, null, $store);
     $this->authRequest->setNonce($nonce);
     $url = $this->authRequest->getAuthorizeURL();
 }