TypeError: Cannot assign string to property Mautic\Auth\TwoLeggedOAuth2::$_expires of type ?int in Mautic\Auth\TwoLeggedOAuth2->setAccessTokenDetails()

Created on 15 July 2025, about 1 month ago

Problem/Motivation

This module uses mautic/api-library and with patch (diff from official library and forked one at https://github.com/nick-vanpraet/api-library/) it uses TwoLeggedOAuth2.php. Here we're getting such error:

TypeError: Cannot assign string to property Mautic\Auth\TwoLeggedOAuth2::$_expires of type ?int in Mautic\Auth\TwoLeggedOAuth2->setAccessTokenDetails() (regel 122 van /var/www/strategica/staging/application/vendor/mautic/api-library/lib/Auth/TwoLeggedOAuth2.php).

Steps to reproduce

Use mautic_paragraph v1.1.1 and mautic/api-library v3.1.0 with patch that is defined in mautic_paragraph composer.json based on https://github.com/mautic/api-library/pull/269/ and you should see AJAX error in console and mentioned error logged in dblog when you try to add Mautic Paragraph from BE.

Proposed resolution

Expires is meant to be of type "int" as it is basically a timestamp and code in TwoLeggedOAuth2.php is using this in combination with time() etc. so it needs to be of type int, but I would say it becomes string when passed from mautic_paragraph or from somewhere else.

Therefore, could you make these changes on your fork of mautic/api-library so that the patch in mautic_paragraph gets updated and uses casting to int as it does on line 205

https://github.com/nick-vanpraet/api-library/blob/628c31fc80fb190435d644...

On this line:
https://github.com/nick-vanpraet/api-library/blob/628c31fc80fb190435d644...

'expires'      => (int) $accessTokenExpires,

Then on this on too:
https://github.com/nick-vanpraet/api-library/blob/628c31fc80fb190435d644...

'expires'      => (int) $this->_expires,

And finally this line alone fixes the error above we're getting on strategica:
https://github.com/nick-vanpraet/api-library/blob/628c31fc80fb190435d644...

$this->_expires      = isset($accessTokenDetails['expires']) ? (int) $accessTokenDetails['expires'] : null;

Also you could do integer casting of "expires" value passed from mautic_paragraph to the library, too.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇷🇸Serbia miksha

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024