E
E
Eugene2020-12-29 15:03:00
OAuth
Eugene, 2020-12-29 15:03:00

Bitrix24 box - OAuth authorization error, where to dig?

There is a Bitrix24 box installed on BitrixEnv.
When trying to install an application, for example Wazzup or exchange with 1C, when authorizing the application, it returns an error
NO_AUTH_DATA
Wrong authorization data

Where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-01-14
@udjin123

In general, I managed to get to the bottom of the problem with a debugger, maybe someone will come in handy.
A couple of facts. Bitrix has a modular structure. Bitrix has a REST API module.
When you install a module, you can register event handlers. When installed, in this case REST Api, registers handlers for different authorization options

if(!\Bitrix\Main\ModuleManager::isModuleInstalled("oauth"))
    {
      $eventManager->registerEventHandler("rest", "onRestCheckAuth", "rest", "\\Bitrix\\Rest\\OAuth\\Auth", "onRestCheckAuth");
    }

    $eventManager->registerEventHandler("rest", "onRestCheckAuth", "rest", "\\Bitrix\\Rest\\APAuth\\Auth", "onRestCheckAuth");
    $eventManager->registerEventHandler("rest", "onRestCheckAuth", "rest", "\\Bitrix\\Rest\\SessionAuth\\Auth", "onRestCheckAuth");

which then, when accessing the api and checking, are sorted out in a loop and authorized depending on the request parameters.
foreach(GetModuleEvents('rest', 'OnRestCheckAuth', true) as $eventHandler)
    {
      $eventResult = ExecuteModuleEventEx($eventHandler, array($query, $scope, &$res));
      if($eventResult !== null)
      {
        return $eventResult;
      }
    }

Please note that in order to register an authorization handler via oAuth, a check is made for the presence of an installed module
if(!\Bitrix\Main\ModuleManager::isModuleInstalled("oauth"))
    {
     $eventManager->registerEventHandler("rest", "onRestCheckAuth", "rest", "\\Bitrix\\Rest\\OAuth\\Auth", "onRestCheckAuth");
   }

So it turns out that at the time of installing the Rest module it was not there because the event was not registered.
For good, reinstalling the Rest module would help, but in the Bitrix24 box it has hard dependencies and this cannot be done without removing the portal floor.
60003859766e3137963019.png
I had to manually register the handler and it all worked.
Conclusion - the Bitrix code, as always, is on top, in creating problems out of the blue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question