3 require_once 'authx.civix.php';
5 use CRM_Authx_ExtensionUtil
as E
;
8 Civi
::dispatcher()->addListener('civi.invoke.auth', function($e) {
9 if (!empty($_SERVER['HTTP_X_CIVI_AUTH'])) {
10 return (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'xheader', 'cred' => $_SERVER['HTTP_X_CIVI_AUTH']]);
13 if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
14 return (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'header', 'cred' => $_SERVER['HTTP_AUTHORIZATION']]);
17 $params = ($_SERVER['REQUEST_METHOD'] === 'GET') ?
$_GET : $_POST;
18 if (!empty($params['_authx'])) {
19 if ((implode('/', $e->args
) === 'civicrm/authx/login')) {
20 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'login', 'cred' => $params['_authx'], 'useSession' => TRUE]);
21 _authx_redact(['_authx']);
23 elseif (!empty($params['_authxSes'])) {
24 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'auto', 'cred' => $params['_authx'], 'useSession' => TRUE]);
25 if ($_SERVER['REQUEST_METHOD'] === 'GET') {
26 _authx_reload(implode('/', $e->args
), $_SERVER['QUERY_STRING']);
29 _authx_redact(['_authx', '_authxSes']);
33 (new \Civi\Authx\
Authenticator())->auth($e, ['flow' => 'param', 'cred' => $params['_authx']]);
34 _authx_redact(['_authx']);
40 * @return \Civi\Authx\AuthxInterface
42 function _authx_uf() {
43 $class = 'Civi\\Authx\\' . CIVICRM_UF
;
44 return class_exists($class) ?
new $class() : new \Civi\Authx\
None();
48 * For parameter-based authentication, this option will hide parameters.
49 * This is mostly a precaution, hedging against the possibility that some routes
50 * make broad use of $_GET or $_PARAMS.
54 function _authx_redact(array $keys) {
55 foreach ($keys as $key) {
56 unset($_POST[$key], $_GET[$key], $_REQUEST[$key]);
61 * Reload the current page-view.
63 * @param string $route
64 * @param string $queryString
66 function _authx_reload($route, $queryString) {
67 parse_str($queryString, $query);
68 foreach (array_keys($query) as $key) {
69 if (CRM_Utils_String
::startsWith($key, '_authx')) {
73 $url = CRM_Utils_System
::url($route, $query, TRUE, NULL, FALSE, CRM_Core_Config
::singleton()->userSystem
->isFrontEndPage());
74 CRM_Utils_System
::redirect($url);
78 * Implements hook_civicrm_config().
80 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
82 function authx_civicrm_config(&$config) {
83 _authx_civix_civicrm_config($config);
87 * Implements hook_civicrm_xmlMenu().
89 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
91 function authx_civicrm_xmlMenu(&$files) {
92 _authx_civix_civicrm_xmlMenu($files);
96 * Implements hook_civicrm_install().
98 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
100 function authx_civicrm_install() {
101 _authx_civix_civicrm_install();
105 * Implements hook_civicrm_postInstall().
107 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
109 function authx_civicrm_postInstall() {
110 _authx_civix_civicrm_postInstall();
114 * Implements hook_civicrm_uninstall().
116 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
118 function authx_civicrm_uninstall() {
119 _authx_civix_civicrm_uninstall();
123 * Implements hook_civicrm_enable().
125 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
127 function authx_civicrm_enable() {
128 _authx_civix_civicrm_enable();
132 * Implements hook_civicrm_disable().
134 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
136 function authx_civicrm_disable() {
137 _authx_civix_civicrm_disable();
141 * Implements hook_civicrm_upgrade().
143 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
145 function authx_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
146 return _authx_civix_civicrm_upgrade($op, $queue);
150 * Implements hook_civicrm_managed().
152 * Generate a list of entities to create/deactivate/delete when this module
153 * is installed, disabled, uninstalled.
155 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
157 function authx_civicrm_managed(&$entities) {
158 _authx_civix_civicrm_managed($entities);
162 * Implements hook_civicrm_caseTypes().
164 * Generate a list of case-types.
166 * Note: This hook only runs in CiviCRM 4.4+.
168 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
170 function authx_civicrm_caseTypes(&$caseTypes) {
171 _authx_civix_civicrm_caseTypes($caseTypes);
175 * Implements hook_civicrm_angularModules().
177 * Generate a list of Angular modules.
179 * Note: This hook only runs in CiviCRM 4.5+. It may
180 * use features only available in v4.6+.
182 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
184 function authx_civicrm_angularModules(&$angularModules) {
185 _authx_civix_civicrm_angularModules($angularModules);
189 * Implements hook_civicrm_alterSettingsFolders().
191 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
193 function authx_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
194 _authx_civix_civicrm_alterSettingsFolders($metaDataFolders);
198 * Implements hook_civicrm_entityTypes().
200 * Declare entity types provided by this module.
202 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
204 function authx_civicrm_entityTypes(&$entityTypes) {
205 _authx_civix_civicrm_entityTypes($entityTypes);
209 * Implements hook_civicrm_thems().
211 function authx_civicrm_themes(&$themes) {
212 _authx_civix_civicrm_themes($themes);
215 // --- Functions below this ship commented out. Uncomment as required. ---
218 * Implements hook_civicrm_preProcess().
220 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
222 //function authx_civicrm_preProcess($formName, &$form) {
227 * Implements hook_civicrm_navigationMenu().
229 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
231 //function authx_civicrm_navigationMenu(&$menu) {
232 // _authx_civix_insert_navigation_menu($menu, 'Mailings', array(
233 // 'label' => E::ts('New subliminal message'),
234 // 'name' => 'mailing_subliminal_message',
235 // 'url' => 'civicrm/mailing/subliminal',
236 // 'permission' => 'access CiviMail',
237 // 'operator' => 'OR',
240 // _authx_civix_navigationMenu($menu);