Commit | Line | Data |
---|---|---|
7946d659 TO |
1 | <?php |
2 | ||
3 | require_once 'authx.civix.php'; | |
4 | // phpcs:disable | |
5 | use CRM_Authx_ExtensionUtil as E; | |
6 | // phpcs:enable | |
7 | ||
3a429e3f TO |
8 | Civi::dispatcher()->addListener('civi.invoke.auth', function($e) { |
9 | if (!empty($_SERVER['HTTP_X_CIVI_AUTH'])) { | |
10 | return (new \Civi\Authx\Authenticator('xheader'))->auth($e, $_SERVER['HTTP_X_CIVI_AUTH']); | |
11 | } | |
12 | ||
13 | if (!empty($_SERVER['HTTP_AUTHORIZATION'])) { | |
14 | return (new \Civi\Authx\Authenticator('header'))->auth($e, $_SERVER['HTTP_AUTHORIZATION']); | |
15 | } | |
16 | ||
17 | $params = ($_SERVER['REQUEST_METHOD'] === 'GET') ? $_GET : $_POST; | |
18 | if (!empty($params['_authx'])) { | |
19 | if ((implode('/', $e->args) === 'civicrm/authx/login')) { | |
d0528c96 | 20 | (new \Civi\Authx\Authenticator('login'))->auth($e, $params['_authx'], TRUE); |
3a429e3f TO |
21 | _authx_redact(['_authx']); |
22 | } | |
23 | elseif (!empty($params['_authxSes'])) { | |
24 | (new \Civi\Authx\Authenticator('auto'))->auth($e, $params['_authx'], TRUE); | |
25 | _authx_redact(['_authx', '_authxSes']); | |
26 | } | |
27 | else { | |
28 | (new \Civi\Authx\Authenticator('param'))->auth($e, $params['_authx']); | |
29 | _authx_redact(['_authx']); | |
30 | } | |
31 | } | |
32 | }); | |
33 | ||
34 | /** | |
35 | * @return \Civi\Authx\AuthxInterface | |
36 | */ | |
37 | function _authx_uf() { | |
38 | $class = 'Civi\\Authx\\' . CIVICRM_UF; | |
39 | return class_exists($class) ? new $class() : new \Civi\Authx\None(); | |
40 | } | |
41 | ||
42 | /** | |
43 | * For parameter-based authentication, this option will hide parameters. | |
44 | * This is mostly a precaution, hedging against the possibility that some routes | |
45 | * make broad use of $_GET or $_PARAMS. | |
46 | * | |
47 | * @param array $keys | |
48 | */ | |
49 | function _authx_redact(array $keys) { | |
50 | foreach ($keys as $key) { | |
51 | unset($_POST[$key], $_GET[$key], $_REQUEST[$key]); | |
52 | } | |
53 | } | |
54 | ||
7946d659 TO |
55 | /** |
56 | * Implements hook_civicrm_config(). | |
57 | * | |
58 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/ | |
59 | */ | |
60 | function authx_civicrm_config(&$config) { | |
61 | _authx_civix_civicrm_config($config); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Implements hook_civicrm_xmlMenu(). | |
66 | * | |
67 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu | |
68 | */ | |
69 | function authx_civicrm_xmlMenu(&$files) { | |
70 | _authx_civix_civicrm_xmlMenu($files); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Implements hook_civicrm_install(). | |
75 | * | |
76 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install | |
77 | */ | |
78 | function authx_civicrm_install() { | |
79 | _authx_civix_civicrm_install(); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Implements hook_civicrm_postInstall(). | |
84 | * | |
85 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall | |
86 | */ | |
87 | function authx_civicrm_postInstall() { | |
88 | _authx_civix_civicrm_postInstall(); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Implements hook_civicrm_uninstall(). | |
93 | * | |
94 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall | |
95 | */ | |
96 | function authx_civicrm_uninstall() { | |
97 | _authx_civix_civicrm_uninstall(); | |
98 | } | |
99 | ||
100 | /** | |
101 | * Implements hook_civicrm_enable(). | |
102 | * | |
103 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable | |
104 | */ | |
105 | function authx_civicrm_enable() { | |
106 | _authx_civix_civicrm_enable(); | |
107 | } | |
108 | ||
109 | /** | |
110 | * Implements hook_civicrm_disable(). | |
111 | * | |
112 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable | |
113 | */ | |
114 | function authx_civicrm_disable() { | |
115 | _authx_civix_civicrm_disable(); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Implements hook_civicrm_upgrade(). | |
120 | * | |
121 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade | |
122 | */ | |
123 | function authx_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { | |
124 | return _authx_civix_civicrm_upgrade($op, $queue); | |
125 | } | |
126 | ||
127 | /** | |
128 | * Implements hook_civicrm_managed(). | |
129 | * | |
130 | * Generate a list of entities to create/deactivate/delete when this module | |
131 | * is installed, disabled, uninstalled. | |
132 | * | |
133 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed | |
134 | */ | |
135 | function authx_civicrm_managed(&$entities) { | |
136 | _authx_civix_civicrm_managed($entities); | |
137 | } | |
138 | ||
139 | /** | |
140 | * Implements hook_civicrm_caseTypes(). | |
141 | * | |
142 | * Generate a list of case-types. | |
143 | * | |
144 | * Note: This hook only runs in CiviCRM 4.4+. | |
145 | * | |
146 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes | |
147 | */ | |
148 | function authx_civicrm_caseTypes(&$caseTypes) { | |
149 | _authx_civix_civicrm_caseTypes($caseTypes); | |
150 | } | |
151 | ||
152 | /** | |
153 | * Implements hook_civicrm_angularModules(). | |
154 | * | |
155 | * Generate a list of Angular modules. | |
156 | * | |
157 | * Note: This hook only runs in CiviCRM 4.5+. It may | |
158 | * use features only available in v4.6+. | |
159 | * | |
160 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules | |
161 | */ | |
162 | function authx_civicrm_angularModules(&$angularModules) { | |
163 | _authx_civix_civicrm_angularModules($angularModules); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Implements hook_civicrm_alterSettingsFolders(). | |
168 | * | |
169 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders | |
170 | */ | |
171 | function authx_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { | |
172 | _authx_civix_civicrm_alterSettingsFolders($metaDataFolders); | |
173 | } | |
174 | ||
175 | /** | |
176 | * Implements hook_civicrm_entityTypes(). | |
177 | * | |
178 | * Declare entity types provided by this module. | |
179 | * | |
180 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes | |
181 | */ | |
182 | function authx_civicrm_entityTypes(&$entityTypes) { | |
183 | _authx_civix_civicrm_entityTypes($entityTypes); | |
184 | } | |
185 | ||
186 | /** | |
187 | * Implements hook_civicrm_thems(). | |
188 | */ | |
189 | function authx_civicrm_themes(&$themes) { | |
190 | _authx_civix_civicrm_themes($themes); | |
191 | } | |
192 | ||
193 | // --- Functions below this ship commented out. Uncomment as required. --- | |
194 | ||
195 | /** | |
196 | * Implements hook_civicrm_preProcess(). | |
197 | * | |
198 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess | |
199 | */ | |
200 | //function authx_civicrm_preProcess($formName, &$form) { | |
201 | // | |
202 | //} | |
203 | ||
204 | /** | |
205 | * Implements hook_civicrm_navigationMenu(). | |
206 | * | |
207 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu | |
208 | */ | |
209 | //function authx_civicrm_navigationMenu(&$menu) { | |
210 | // _authx_civix_insert_navigation_menu($menu, 'Mailings', array( | |
211 | // 'label' => E::ts('New subliminal message'), | |
212 | // 'name' => 'mailing_subliminal_message', | |
213 | // 'url' => 'civicrm/mailing/subliminal', | |
214 | // 'permission' => 'access CiviMail', | |
215 | // 'operator' => 'OR', | |
216 | // 'separator' => 0, | |
217 | // )); | |
218 | // _authx_civix_navigationMenu($menu); | |
219 | //} |