-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
authx - Allow
civicrm/ajax/rest
to accept auth params akin to `exte…
…rn/rest.php`
- Loading branch information
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Authx; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
|
||
/** | ||
* Historically, 'extern/rest.php' and 'civicrm/ajax/rest' were similar interfaces | ||
* based on the same controller, but they used different authentication styles. | ||
* | ||
* This authenticator is activated if one requests 'civicrm/ajax/rest' using the | ||
* authentication style of 'extern/rest.php'. | ||
* | ||
* @package Civi\Authx | ||
*/ | ||
class LegacyRestAuthenticator extends Authenticator { | ||
|
||
protected function reject($message = 'Authentication failed') { | ||
$data = ["error_message" => "FATAL: $message", "is_error" => 1]; | ||
$r = new Response(200, ['Content-Type' => 'text/javascript'], json_encode($data)); | ||
\CRM_Utils_System::sendResponse($r); | ||
} | ||
|
||
protected function login(AuthenticatorTarget $tgt) { | ||
parent::login($tgt); | ||
\Civi::dispatcher()->addListener('hook_civicrm_permission_check', function ($e) { | ||
if ($e->permission === 'access AJAX API') { | ||
$e->granted = TRUE; | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Verify that the REST API bindings correctly parse and authenticate requests. | ||
* | ||
* @group e2e | ||
*/ | ||
class E2E_Extern_AuthxRestTest extends E2E_Extern_BaseRestTest { | ||
|
||
public static function setUpBeforeClass() { | ||
parent::setUpBeforeClass(); | ||
\Civi\Test::e2e() | ||
->install(['authx']) | ||
->callback( | ||
function() { | ||
\CRM_Utils_System::synchronizeUsers(); | ||
}, | ||
'synchronizeUsers' | ||
) | ||
->apply(); | ||
} | ||
|
||
protected function getRestUrl() { | ||
return CRM_Utils_System::url('civicrm/ajax/rest', NULL, TRUE, NULL, FALSE, TRUE); | ||
} | ||
|
||
public function apiTestCases() { | ||
$r = parent::apiTestCases(); | ||
$r = array_filter($r, function($case) { | ||
// The 'civicrm/ajax/rest' end-point does not support '?q' inputs. | ||
return !isset($case[0]['q']); | ||
}); | ||
return $r; | ||
} | ||
|
||
} |