0

We have local and dev site with drupal 8 + CiviCRM 5.22.0, Installed Contact Layout Editor Extension.

http://localdemo8.com/civicrm/api4. (api4 explorer)

or

http://localdemo8.com/civicrm/ajax/api4 for contact layout api call.

we are getting 500 status with 'Authorization failed' Message in console.

Here is backtrace

$Fatal Error Details = array(3) {
  ["message"]=>
  string(20) "Authorization failed"
  ["code"]=>
  NULL
  ["exception"]=>
  array(8) {
    ["API_ExceptionextraParams"]=>
    string(39) "#0 [internal function](): ()
#1 {main}
"
    ["*message"]=>
    string(20) "Authorization failed"
    ["Exceptionstring"]=>
    string(0) ""
    ["*code"]=>
    int(0)
    ["*file"]=>
    string(103) "PATH/vendor/civicrm/civicrm-core/Civi/API/Kernel.php"
    ["*line"]=>
    int(224)
    ["Exceptiontrace"]=>
    string(4877) "#0 PATH/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(150): Civi\API\Kernel->authorize(Object(Civi\Api4\Provider\ActionObjectProvider), Object(Civi\Api4\Action\Entity\Get))
#1 PATH/vendor/civicrm/civicrm-core/Civi/Api4/Generic/AbstractAction.php(219): Civi\API\Kernel->runRequest(Object(Civi\Api4\Action\Entity\Get))
#2 PATH/vendor/civicrm/civicrm-core/CRM/Api4/Page/Api4Explorer.php(26): Civi\Api4\Generic\AbstractAction->execute()
#3 PATH/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(268): CRM_Api4_Page_Api4Explorer->run((Array:2), NULL)
#4 PATH/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
#5 PATH/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:2))
#6 PATH/web/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke((Array:2))
#7 PATH/web/modules/contrib/civicrm/src/Controller/CivicrmController.php(75): Drupal\civicrm\Civicrm->invoke((Array:2))
#8 [internal function](): Drupal\civicrm\Controller\CivicrmController->main((Array:2), "")
#9 PATH/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array((Array:2), (Array:2))
#10 PATH/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 PATH/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#12 PATH/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext((Array:2), (Array:2))
#13 PATH/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 PATH/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#15 PATH/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#16 PATH/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#17 PATH/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#18 PATH/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#19 PATH/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#20 PATH/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#21 PATH/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#22 PATH/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
#23 PATH/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))

Anybody have an idea about this issue ?

1
  • any body have idea ? Apr 22, 2020 at 15:25

1 Answer 1

2

Following changes fix the issue,

diff --git a/Civi/API/Subscriber/PermissionCheck.php b/Civi/API/Subscriber/PermissionCheck.php
index bc2f18af..282b9faa 100644
--- a/Civi/API/Subscriber/PermissionCheck.php
+++ b/Civi/API/Subscriber/PermissionCheck.php
@@ -76,7 +76,7 @@ class PermissionCheck implements EventSubscriberInterface {
       $event->stopPropagation();
     }
     elseif ($apiRequest['version'] == 4) {
-      if (!$apiRequest->getCheckPermissions()) {
+      if (!$apiRequest->getCheckPermissions() || $apiRequest->isAuthorized()) {
         $event->authorize();
         $event->stopPropagation();
       }
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.