Ejemplo n.º 1
0
 function _runTest()
 {
     // Do one parse, after which arrayToKV and kvToArray should be
     // inverses.
     $parsed1 = Auth_OpenID_KVForm::toArray($this->str);
     $serial1 = Auth_OpenID_KVForm::fromArray($this->arr);
     if ($this->lossy == "neither" || $this->lossy == "str") {
         $this->assertEquals($this->arr, $parsed1, "str was lossy");
     }
     if ($this->lossy == "neither" || $this->lossy == "arr") {
         $this->assertEquals($this->str, $serial1, "array was lossy");
     }
     $parsed2 = Auth_OpenID_KVForm::toArray($serial1);
     $serial2 = Auth_OpenID_KVForm::fromArray($parsed1);
     // Round-trip both
     $parsed3 = Auth_OpenID_KVForm::toArray($serial2);
     $serial3 = Auth_OpenID_KVForm::fromArray($parsed2);
     $this->assertEquals($serial2, $serial3, "serialized forms differ");
     // Check to make sure that they're inverses.
     $this->assertEquals($parsed2, $parsed3, "parsed forms differ");
 }
Ejemplo n.º 2
0
 /**
  * Parse an association as stored by serialize().  This is the
  * inverse of serialize.
  *
  * @param string $assoc_s Association as serialized by serialize()
  * @return Auth_OpenID_Association $result instance of this class
  */
 function deserialize($class_name, $assoc_s)
 {
     $pairs = Auth_OpenID_KVForm::toArray($assoc_s, $strict = true);
     $keys = array();
     $values = array();
     foreach ($pairs as $key => $value) {
         if (is_array($value)) {
             list($key, $value) = $value;
         }
         $keys[] = $key;
         $values[] = $value;
     }
     $class_vars = get_class_vars($class_name);
     $class_assoc_keys = $class_vars['assoc_keys'];
     sort($keys);
     sort($class_assoc_keys);
     if ($keys != $class_assoc_keys) {
         trigger_error('Unexpected key values: ' . var_export($keys, true), E_USER_WARNING);
         return null;
     }
     $version = $pairs['version'];
     $handle = $pairs['handle'];
     $secret = $pairs['secret'];
     $issued = $pairs['issued'];
     $lifetime = $pairs['lifetime'];
     $assoc_type = $pairs['assoc_type'];
     if ($version != '2') {
         trigger_error('Unknown version: ' . $version, E_USER_WARNING);
         return null;
     }
     $issued = intval($issued);
     $lifetime = intval($lifetime);
     $secret = base64_decode($secret);
     return new $class_name($handle, $secret, $issued, $lifetime, $assoc_type);
 }
Ejemplo n.º 3
0
 function fromKVForm($kvform_string)
 {
     // Create a Message from a KVForm string
     return Auth_OpenID_Message::fromOpenIDArgs(Auth_OpenID_KVForm::toArray($kvform_string));
 }
Ejemplo n.º 4
0
 /**
  * @access private
  */
 function _makeKVPost($args, $server_url)
 {
     $mode = $args['openid.mode'];
     $pairs = array();
     foreach ($args as $k => $v) {
         $v = urlencode($v);
         $pairs[] = "{$k}={$v}";
     }
     $body = implode("&", $pairs);
     $resp = $this->fetcher->post($server_url, $body);
     if ($resp === null) {
         return null;
     }
     $response = Auth_OpenID_KVForm::toArray($resp->body);
     if ($resp->status == 400) {
         return null;
     } else {
         if ($resp->status != 200) {
             return null;
         }
     }
     return $response;
 }