Handling user-related SDK CRest

As a standard, CRest library is applicable to a user who installed the application. However, sometimes Bitrix24 account must be queried under a user with tokens received to POST page. For example, when such user opens your embedded application. To accomplish this, CRest methods can be inherited:

require_once(__DIR__ . '/crest.php');
class CRestCurrent extends CRest
   protected static $dataExt = [];
   protected static function getSettingData()
      $return = static::expandData(file_get_contents(__DIR__ . '/settings.json'));
            $return['access_token'] = htmlspecialchars(static::$dataExt['AUTH_ID']);
            $return['domain'] = htmlspecialchars(static::$dataExt['DOMAIN']);
            $return['refresh_token'] = htmlspecialchars(static::$dataExt['REFRESH_ID']);
            $return['application_token'] = htmlspecialchars(static::$dataExt['APP_SID']);
            $return['access_token'] = htmlspecialchars($_REQUEST['AUTH_ID']);
            $return['domain'] = htmlspecialchars($_REQUEST['DOMAIN']);
            $return['refresh_token'] = htmlspecialchars($_REQUEST['REFRESH_ID']);
            $return['application_token'] = htmlspecialchars($_REQUEST['APP_SID']);


      return $return;

   public static function setDataExt($data)
      static::$dataExt = $data;

After that, you can use file with new class in your code and use current user methods, when page has the tokens.
You can check method's operation by calling this method:

$result = CRestCurrent::call('user.current');

echo '<pre>';
echo '</pre>';
© «Bitrix Inc.», 2001-2021, «Bitrix Inc.», 2021