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>';

User Comments

User comments are not part of official documentation. Use information provided by other users in the comments at your own risk.

The User Comments section is not to be used as a feature discussion board. Only registered users can post comments. Your comment will be visible once it has been approved by the moderator.
© «Bitrix Inc.», 2001-2021, «Bitrix Inc.», 2021