Answers.Body: <p>Following changes fix the issue,</p>
  
  <pre><code>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-&gt;stopPropagation();
       }
       elseif ($apiRequest['version'] == 4) {
  -      if (!$apiRequest-&gt;getCheckPermissions()) {
  +      if (!$apiRequest-&gt;getCheckPermissions() || $apiRequest-&gt;isAuthorized()) {
           $event-&gt;authorize();
           $event-&gt;stopPropagation();
         }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-25T09:31:23.130Z
Answers.Text: Is there any PR submitted for the above patch?
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-31T13:23:03.417Z
Answers.Text: It should not be necessary to apply this patch. If you encountered  this in 5.49 like I did, it was fixed by: https://github.com/civicrm/civicrm-core/pull/23611
Answers.UserDisplayName: bgm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-23T04:11:07.450Z
Answers.LastActivityDate: 2020-04-23T04:11:07.450Z
Answers.UserDisplayName: Sunil Pawar
Body: <p>We have local and dev site with drupal 8 + CiviCRM 5.22.0, Installed Contact Layout Editor Extension.</p>
  
  <p><a href="http://localdemo8.com/civicrm/api4" rel="nofollow noreferrer">http://localdemo8.com/civicrm/api4</a>. (api4 explorer)</p>
  
  <p>or</p>
  
  <p><a href="http://localdemo8.com/civicrm/ajax/api4" rel="nofollow noreferrer">http://localdemo8.com/civicrm/ajax/api4</a> for contact layout api call.</p>
  
  <p>we are getting 500 status with 'Authorization failed' Message in console.</p>
  
  <p>Here is backtrace </p>
  
  <pre><code>$Fatal Error Details = array(3) {
    ["message"]=&gt;
    string(20) "Authorization failed"
    ["code"]=&gt;
    NULL
    ["exception"]=&gt;
    array(8) {
      ["API_ExceptionextraParams"]=&gt;
      string(39) "#0 [internal function](): ()
  #1 {main}
  "
      ["*message"]=&gt;
      string(20) "Authorization failed"
      ["Exceptionstring"]=&gt;
      string(0) ""
      ["*code"]=&gt;
      int(0)
      ["*file"]=&gt;
      string(103) "PATH/vendor/civicrm/civicrm-core/Civi/API/Kernel.php"
      ["*line"]=&gt;
      int(224)
      ["Exceptiontrace"]=&gt;
      string(4877) "#0 PATH/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(150): Civi\API\Kernel-&gt;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-&gt;runRequest(Object(Civi\Api4\Action\Entity\Get))
  #2 PATH/vendor/civicrm/civicrm-core/CRM/Api4/Page/Api4Explorer.php(26): Civi\Api4\Generic\AbstractAction-&gt;execute()
  #3 PATH/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(268): CRM_Api4_Page_Api4Explorer-&gt;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-&gt;invoke((Array:2))
  #8 [internal function](): Drupal\civicrm\Controller\CivicrmController-&gt;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-&gt;Drupal\Core\EventSubscriber\{closure}()
  #11 PATH/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
  #12 PATH/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext((Array:2), (Array:2))
  #13 PATH/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}()
  #14 PATH/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
  #15 PATH/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #16 PATH/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #17 PATH/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle-&gt;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-&gt;pass(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #19 PATH/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #20 PATH/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #21 PATH/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #22 PATH/web/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\StackedHttpKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request), 1, TRUE)
  #23 PATH/web/index.php(19): Drupal\Core\DrupalKernel-&gt;handle(Object(Symfony\Component\HttpFoundation\Request))
  </code></pre>
  
  <p>Anybody have an idea about this issue ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-22T15:25:38.920Z
Comments.Text: any body have idea ?
Comments.UserDisplayName: Sunil Pawar
Tags: <api><drupal-8>
Title: API4 giving Authorization failed Error
ThreadText: # API4 giving Authorization failed Error
  
  (Asked by: username_0 on 2020-04-17)
  
  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 ?
  
  **Tags:** api, drupal-8
  
  > **Comments:**
  > **username_0**: any body have idea ?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-23. Score: 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();
         }
  
  ```
  
  > **Comments:**
  > **username_1**: Is there any PR submitted for the above patch?  
  > **username_2**: It should not be necessary to apply this patch. If you encountered  this in 5.49 like I did, it was fixed by: https://github.com/civicrm/civicrm-core/pull/23611  
  
  ---
  
  