3 require_once 'authx.civix.php';
5 use CRM_Authx_ExtensionUtil
as E
;
8 Civi
::dispatcher()->addListener('civi.invoke.auth', function($e) {
9 $params = ($_SERVER['REQUEST_METHOD'] === 'GET') ?
$_GET : $_POST;
10 $siteKey = $_SERVER['HTTP_X_CIVI_KEY'] ??
$params['_authxSiteKey'] ??
NULL;
12 if (!empty($_SERVER['HTTP_X_CIVI_AUTH'])) {
13 return (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'xheader', 'cred' => $_SERVER['HTTP_X_CIVI_AUTH'], 'siteKey' => $siteKey]);
16 if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
17 return (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'header', 'cred' => $_SERVER['HTTP_AUTHORIZATION'], 'siteKey' => $siteKey]);
20 if (!empty($params['_authx'])) {
21 if ((implode('/', $e->args
) === 'civicrm/authx/login')) {
22 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'login', 'cred' => $params['_authx'], 'useSession' => TRUE, 'siteKey' => $siteKey]);
23 _authx_redact(['_authx']);
25 elseif (!empty($params['_authxSes'])) {
26 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'auto', 'cred' => $params['_authx'], 'useSession' => TRUE, 'siteKey' => $siteKey]);
27 if ($_SERVER['REQUEST_METHOD'] === 'GET') {
28 _authx_reload(implode('/', $e->args
), $_SERVER['QUERY_STRING']);
31 _authx_redact(['_authx', '_authxSes']);
35 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'param', 'cred' => $params['_authx'], 'siteKey' => $siteKey]);
36 _authx_redact(['_authx']);
42 * @return \Civi\Authx\AuthxInterface
44 function _authx_uf() {
45 $class = 'Civi\\Authx\\' . CIVICRM_UF
;
46 return class_exists($class) ?
new $class() : new \Civi\Authx\
None();
50 * For parameter-based authentication, this option will hide parameters.
51 * This is mostly a precaution, hedging against the possibility that some routes
52 * make broad use of $_GET or $_PARAMS.
56 function _authx_redact(array $keys) {
57 foreach ($keys as $key) {
58 unset($_POST[$key], $_GET[$key], $_REQUEST[$key]);
63 * Reload the current page-view.
65 * @param string $route
66 * @param string $queryString
68 function _authx_reload($route, $queryString) {
69 parse_str($queryString, $query);
70 foreach (array_keys($query) as $key) {
71 if (CRM_Utils_String
::startsWith($key, '_authx')) {
75 $url = CRM_Utils_System
::url($route, $query, TRUE, NULL, FALSE, CRM_Core_Config
::singleton()->userSystem
->isFrontEndPage());
76 CRM_Utils_System
::redirect($url);
80 * Implements hook_civicrm_config().
82 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
84 function authx_civicrm_config(&$config) {
85 _authx_civix_civicrm_config($config);
89 * Implements hook_civicrm_xmlMenu().
91 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
93 function authx_civicrm_xmlMenu(&$files) {
94 _authx_civix_civicrm_xmlMenu($files);
98 * Implements hook_civicrm_install().
100 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
102 function authx_civicrm_install() {
103 _authx_civix_civicrm_install();
107 * Implements hook_civicrm_postInstall().
109 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
111 function authx_civicrm_postInstall() {
112 _authx_civix_civicrm_postInstall();
116 * Implements hook_civicrm_uninstall().
118 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
120 function authx_civicrm_uninstall() {
121 _authx_civix_civicrm_uninstall();
125 * Implements hook_civicrm_enable().
127 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
129 function authx_civicrm_enable() {
130 _authx_civix_civicrm_enable();
134 * Implements hook_civicrm_disable().
136 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
138 function authx_civicrm_disable() {
139 _authx_civix_civicrm_disable();
143 * Implements hook_civicrm_upgrade().
145 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
147 function authx_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
148 return _authx_civix_civicrm_upgrade($op, $queue);
152 * Implements hook_civicrm_managed().
154 * Generate a list of entities to create/deactivate/delete when this module
155 * is installed, disabled, uninstalled.
157 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
159 function authx_civicrm_managed(&$entities) {
160 _authx_civix_civicrm_managed($entities);
164 * Implements hook_civicrm_caseTypes().
166 * Generate a list of case-types.
168 * Note: This hook only runs in CiviCRM 4.4+.
170 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
172 function authx_civicrm_caseTypes(&$caseTypes) {
173 _authx_civix_civicrm_caseTypes($caseTypes);
177 * Implements hook_civicrm_angularModules().
179 * Generate a list of Angular modules.
181 * Note: This hook only runs in CiviCRM 4.5+. It may
182 * use features only available in v4.6+.
184 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
186 function authx_civicrm_angularModules(&$angularModules) {
187 _authx_civix_civicrm_angularModules($angularModules);
191 * Implements hook_civicrm_alterSettingsFolders().
193 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
195 function authx_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
196 _authx_civix_civicrm_alterSettingsFolders($metaDataFolders);
200 * Implements hook_civicrm_entityTypes().
202 * Declare entity types provided by this module.
204 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
206 function authx_civicrm_entityTypes(&$entityTypes) {
207 _authx_civix_civicrm_entityTypes($entityTypes);
211 * Implements hook_civicrm_thems().
213 function authx_civicrm_themes(&$themes) {
214 _authx_civix_civicrm_themes($themes);
218 * Implements hook_civicrm_permission().
220 * @see CRM_Utils_Hook::permission()
222 function authx_civicrm_permission(&$permissions) {
223 $permissions['authenticate with password'] = E
::ts('AuthX: Authenticate to services with password');
224 $permissions['authenticate with api key'] = E
::ts('AuthX: Authenticate to services with API key');
227 // --- Functions below this ship commented out. Uncomment as required. ---
230 * Implements hook_civicrm_preProcess().
232 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
234 //function authx_civicrm_preProcess($formName, &$form) {
239 * Implements hook_civicrm_navigationMenu().
241 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
243 //function authx_civicrm_navigationMenu(&$menu) {
244 // _authx_civix_insert_navigation_menu($menu, 'Mailings', array(
245 // 'label' => E::ts('New subliminal message'),
246 // 'name' => 'mailing_subliminal_message',
247 // 'url' => 'civicrm/mailing/subliminal',
248 // 'permission' => 'access CiviMail',
249 // 'operator' => 'OR',
252 // _authx_civix_navigationMenu($menu);