Problem/Motivation

Sometime we got token error, coz refresh fun on preprecces didn't run

Steps to reproduce

Create webform and attach b24 integration
For some reason token refresh on preprocess func not work correctly and we got error like this one:
Bitrix24 method «crm.lead.add» error: The access token provided has expired..

Proposed resolution

Is it better to check token before request is send?
In the current solution we have a service with the method 'get':

      $request = $this->httpClient->get($uri);
      $this->refreshAccessToken();
      return Json::decode($request->getBody());

So we send a request and after that refresh token each time. My purpose: update token before request is send or check token expired time inside service get method:

      $this->refreshAccessToken();
      $request = $this->httpClient->get($uri);
      return Json::decode($request->getBody());
  $expires = \Drupal::state()->get('b24_token_expires');
  $current_time = \Drupal::service('datetime.time')->getCurrentTime();
  if (($expires - $current_time) < 1800) {
    $this->refreshAccessToken();
  }
  $request = $this->httpClient->get($uri);
  return Json::decode($request->getBody());

It makes sense coz probably we don't need refreshed tokens after request

Issue fork b24-3221679

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pi0ne3r created an issue. See original summary.

artem_kondra’s picture

Issue summary: View changes

Alezu made their first commit to this issue’s fork.

  • Alezu committed aea36e1 on 8.x-1.x authored by pi0ne3r
    Issue #3221679: Access token refresh not work correctly
    
alezu’s picture

Status: Active » Fixed

Hi @pi0ne3r,
Thanks for the fix, I've merged it in a new release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.