/** * Gets the auth request message in a URL format suitable for redirection. The * decision about whether to use directed identity or not id done here. * * @return string The URL to redirect the User-Agent to */ public function getAuthorizeURL() { $version = OpenID::$versionMap[$this->serviceEndpoint->getVersion()]; if ($this->serviceEndpoint->getVersion() == OpenID::SERVICE_2_0_SERVER) { $this->message->set('openid.claimed_id', OpenID::NS_2_0_ID_SELECT); $this->message->set('openid.identity', OpenID::NS_2_0_ID_SELECT); } else { $localID = $this->serviceEndpoint->getLocalID(); if (!empty($localID)) { if ($version == OpenID::NS_2_0) { $this->message->set('openid.claimed_id', $this->identifier); } $this->message->set('openid.identity', $localID); } else { if ($version == OpenID::NS_2_0) { $this->message->set('openid.claimed_id', $this->identifier); } $this->message->set('openid.identity', $this->identifier); } } if ($version == OpenID::NS_1_1) { $this->addNonce(); } $urls = $this->serviceEndpoint->getURIs(); if (strstr($urls[0], '?')) { $url = $urls[0] . '&' . $this->message->getHTTPFormat(); } else { $url = $urls[0] . '?' . $this->message->getHTTPFormat(); } $netURL = new Net_URL2($url); return $netURL->getURL(); }
/** * testSetMessage * * @return void */ public function testSetMessage() { // KV $kv = "openid.foo:foo bar\nopenid.bar:foo bar\n"; // Test constructor setting $this->object = new OpenID_Message($kv, OpenID_Message::FORMAT_KV); $this->assertSame($kv, $this->object->getKVFormat()); // HTTP $http = "openid.foo=foo+bar&openid.bar=foo+bar"; $this->object->setMessage($http, OpenID_Message::FORMAT_HTTP); $this->assertSame($http, $this->object->getHTTPFormat()); // Array $array = array('openid.foo' => 'foo bar', 'openid.bar' => 'foo bar'); $this->object->setMessage($array, OpenID_Message::FORMAT_ARRAY); $this->assertSame($array, $this->object->getArrayFormat()); }
/** * testValidateReturnToOneOneImmediateNegative * * @return void */ public function testValidateReturnToOneOneImmediateNegative() { $opEndpoint = new OpenID_ServiceEndpoint(); $opEndpoint->setURIs(array($this->opEndpointURL)); $opEndpoints = new OpenID_ServiceEndpoints($this->claimedID, $opEndpoint); $nonce = new OpenID_Nonce($this->opEndpointURL); $nonceValue = $nonce->createNonce(); $rt = new Net_URL2('http://examplerp.com'); $rt->setQueryVariable(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $setupMessage = new OpenID_Message(); $setupMessage->set('openid.identity', $this->claimedID); $setupMessage->set('openid.return_to', $rt->getURL()); $setupMessage->set(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $this->message = new OpenID_Message(); $this->message->set('openid.mode', OpenID::MODE_ID_RES); $this->message->set(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $this->message->set('openid.user_setup_url', 'http://examplerp.com/?' . $setupMessage->getHTTPFormat()); $this->discover = $this->getMock('OpenID_Discover', array('__get'), array($this->claimedID)); $this->discover->expects($this->once())->method('__get')->will($this->returnValue($opEndpoints)); $this->store->expects($this->once())->method('getDiscover')->will($this->returnValue($this->discover)); $this->store->expects($this->any())->method('getNonce')->will($this->returnValue($nonceValue)); $this->createObjects(); }
/** * Sends a direct HTTP request. * * @param string $url URL to send the request to * @param OpenID_Message $message Contains message contents * @param array $options Options to pass to HTTP_Request2 * * @see getHTTPRequest2Instance() * @throws OpenID_Exception if send() fails * @return HTTP_Request2_Response */ public function directRequest($url, OpenID_Message $message, array $options = array()) { $request = $this->getHTTPRequest2Instance(); $request->setConfig($options); $request->setURL($url); // Require POST, per the spec $request->setMethod(HTTP_Request2::METHOD_POST); $request->setBody($message->getHTTPFormat()); try { return $request->send(); } catch (HTTP_Request2_Exception $e) { throw new OpenID_Exception($e->getMessage(), $e->getCode()); } }
/** * Converts an OpenID_Message instance to a Net_URL2 instance based on * $this->returnTo. This was added to ease the transition from the old * verify() signature to the new one. * * @param OpenID_Message $message Instance of OpenID_Message * * @return Net_URL2 */ protected function messageToNetURL2(OpenID_Message $message) { return new Net_URL2($this->returnTo . '?' . $message->getHTTPFormat()); }