public static function associate($server) { $data = URLBuilder::buildAssociate($server); try { $res = Poster::post($server, $data); } catch (Exception $ex) { return; } $data = array(); foreach (explode("\n", $res) as $line) { if (preg_match('/^(.*?):(.*)$/', $line, $m)) { $data[$m[1]] = $m[2]; } } $data['expires_at'] = time() + $data['expires_in']; self::$data[$server][$data['assoc_handle']] = $data; self::saveData(); }
/** * Attempts to associate with the specified server. * * @param String $server The server to associate with */ public static function associate($server, $assocType = null, $sessionType = null) { Logger::log('Attempting to associate with %s, assocType: %s, sessionType: %s', $server, $assocType, $sessionType); $data = URLBuilder::buildAssociate($server, $_SESSION['openid']['version'], $assocType, $sessionType); try { $res = Poster::post($server, $data); } catch (Exception $ex) { Logger::log('Exception while posting: %s', $ex->getMessage()); return; } $data = array(); foreach (explode("\n", $res) as $line) { if (preg_match('/^(.*?):(.*)$/', $line, $m)) { $data[$m[1]] = $m[2]; } } if (isset($data['error_code']) && $data['error_code'] == 'unsupported-type') { $cont = false; if (isset($data['session_type']) && $data['session_type'] != $sessionType) { // TODO: Check we support it before actually trying $sessionType = $data['session_type']; $cont = true; } if (isset($data['assoc_type']) && $data['assoc_type'] != $assocType) { $assocType = $data['assoc_type']; $cont = true; } if ($cont) { self::associate($server, $assocType, $sessionType); } return; } try { $data = self::decodeKey($server, $data); } catch (Exception $ex) { return; } $data['expires_at'] = time() + $data['expires_in']; self::$data[$server][$data['assoc_handle']] = $data; self::saveData(); }