function _civicrm_api3_cxn_register_spec(&$spec) {
$daoFields = CRM_Cxn_DAO_Cxn::fields();
$spec['app_guid'] = $daoFields['app_guid'];
-
- if (!CRM_Cxn_BAO_Cxn::isAppMetaVerified()) {
- $spec['app_meta_url'] = array(
- 'name' => 'app_meta_url',
- 'type' => CRM_Utils_Type::T_STRING,
- 'title' => ts('Application Metadata URL'),
- 'description' => 'Application Metadata URL',
- 'maxlength' => 255,
- 'size' => CRM_Utils_Type::HUGE,
- );
- }
+ $spec['app_meta_url'] = array(
+ 'name' => 'app_meta_url',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'title' => ts('Application Metadata URL'),
+ 'description' => 'Application Metadata URL',
+ 'maxlength' => 255,
+ 'size' => CRM_Utils_Type::HUGE,
+ );
}
/**
*/
function civicrm_api3_cxn_register($params) {
if (!empty($params['app_meta_url'])) {
- if (!CRM_Cxn_BAO_Cxn::isAppMetaVerified()) {
- list ($status, $json) = CRM_Utils_HttpClient::singleton()->get($params['app_meta_url']);
- if (CRM_Utils_HttpClient::STATUS_OK != $status) {
- throw new API_Exception("Failed to download appMeta.");
- }
- $appMeta = json_decode($json, TRUE);
+ list ($status, $json) = CRM_Utils_HttpClient::singleton()->get($params['app_meta_url']);
+ if (CRM_Utils_HttpClient::STATUS_OK != $status) {
+ throw new API_Exception("Failed to download appMeta. (Bad HTTP response)");
}
- else {
- // Note: The metadata includes a cert, but the details aren't signed.
- // This is very useful in testing/development. In ordinary usage, we
- // rely on civicrm.org to sign the metadata for all apps en masse.
- throw new API_Exception('This site is configured to only connect to applications with verified metadata.');
+ $appMeta = json_decode($json, TRUE);
+ if (empty($appMeta)) {
+ throw new API_Exception("Failed to download appMeta. (Malformed)");
}
}
elseif (!empty($params['app_guid'])) {
* @return array
*/
function civicrm_api3_cxn_unregister($params) {
+ $cxnId = _civicrm_api3_cxn_parseCxnId($params);
+ $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
+
+ /** @var \Civi\Cxn\Rpc\RegistrationClient $client */
+ $client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
+ list($cxnId, $result) = $client->unregister($appMeta, CRM_Utils_Array::value('force', $params, FALSE));
+
+ return $result;
+}
+
+/**
+ * @param array $params
+ * An array with cxn_guid and/or app_guid.
+ * @return string
+ * The CxnId. (If not available, then an exception is thrown.)
+ *
+ * @throws API_Exception
+ */
+function _civicrm_api3_cxn_parseCxnId($params) {
$cxnId = NULL;
if (!empty($params['cxn_guid'])) {
if (!$cxnId) {
throw new API_Exception('Missing required parameter: cxn_guid');
}
+ return $cxnId;
+}
- $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
-
- /** @var \Civi\Cxn\Rpc\RegistrationClient $client */
- $client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
- list($cxnId, $result) = $client->unregister($appMeta, CRM_Utils_Array::value('force', $params, FALSE));
-
- return $result;
+function _civicrm_api3_cxn_get_spec(&$spec) {
+ // Don't trust AJAX callers or other external code to modify, filter, or return the secret.
+ unset($spec['secret']);
}
/**
* API result array.
*/
function civicrm_api3_cxn_get($params) {
+ // Don't trust AJAX callers or other external code to modify, filter, or return the secret.
+ unset($params['secret']);
+
$result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
if (is_array($result['values'])) {
foreach (array_keys($result['values']) as $i) {
if (!empty($result['values'][$i]['perm'])) {
$result['values'][$i]['perm'] = json_decode($result['values'][$i]['perm'], TRUE);
}
+ // Don't trust AJAX callers or other external code to modify, filter, or return the secret.
+ unset($result['values'][$i]['secret']);
}
}
+
return $result;
}
+
+/**
+ * Adjust metadata for "getlink" action.
+ *
+ * @param array $spec
+ * List of fields.
+ */
+function _civicrm_api3_cxn_getlink_spec(&$spec) {
+ $daoFields = CRM_Cxn_DAO_Cxn::fields();
+ $spec['app_guid'] = $daoFields['app_guid'];
+ $spec['cxn_guid'] = $daoFields['cxn_guid'];
+ $spec['page'] = array(
+ 'name' => 'page',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'title' => ts('Page Type'),
+ 'description' => 'The type of page (eg "settings")',
+ 'maxlength' => 63,
+ 'size' => CRM_Utils_Type::HUGE,
+ );
+}
+
+/**
+ *
+ * @param array $params
+ * Array with keys:
+ * - cxn_guid OR app_guid: string.
+ * - page: string.
+ * @return array
+ * @throws Exception
+ */
+function civicrm_api3_cxn_getlink($params) {
+ $cxnId = _civicrm_api3_cxn_parseCxnId($params);
+ $appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
+
+ if (empty($params['page']) || !is_string($params['page'])) {
+ throw new API_Exception("Invalid page");
+ }
+
+ /** @var \Civi\Cxn\Rpc\RegistrationClient $client */
+ $client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
+ return $client->call($appMeta, 'Cxn', 'getlink', array(
+ 'page' => $params['page'],
+ ));
+}