- edited description
Frontend returns error on parseJwt method
TYPO3 11.5.31 - multisite installation
EXT:nnrestapi 1.4.1
PHP 8.1
On a local ddev installation
I did find that the settings for site configuration was loaded. The same regarding the typoscript configuration.
Just viewing the frontend, returns
#1476107295 TYPO3\CMS\Core\Error\Exception
PHP Runtime Deprecation Notice: explode(): Passing null to parameter ($string) of type string is deprecated in /var/www/html/public/typo3conf/ext/nnhelpers/Classes/Utilities/Encrypt.php line 336#2
\$token here is null and is generated from getBearerToken
public function parseJwt( $token = '' ) {
$parts = explode('.', $token);
I tried to modify the code to:
* ```
* @param string|null $token
* @return array|false
*/
public function parseJwt( $token = '' ) {
if($token===null) return false;
Which makes the frontend work again. But then I get another error when trying to test API from the RestApi BE module:
#1476107295 TYPO3\CMS\Core\Error\Exception
PHP Warning: Undefined array key "response" in /var/www/html/public/typo3conf/ext/nnrestapi/Classes/Utilities/Header.php line 37
Comments (7)
-
reporter -
reporter I have reset my changes I made in the code, and I don’t know why the frontend seems to work now.
The backend module still gives errors, but only if have logged in through a domain which has no site configured.
Would be nice with a meaningful error in this case.
-
reporter Ok. So I did not reset my changes after all. I forgot that the changes were in nnhelpers and not nnrestapi.
So this happens, because there were found no bearer token in the headers in \Nng\Nnhelpers\Utilities\Request::getJwt from the getBearerToken() method.
Would this be expected? If, then why?
If not always expected, shouldn’t parseJwt() return false if null was passed to the method?
-
reporter - edited description
-
reporter A check in parseJwt() could be:
public function parseJwt( $token = '' ) { $parts = explode('.', (string)$token); if(count($parts) !== 3) return false;
or
public function parseJwt( $token = '' ) { if(substr_count((string)$token, '.') !== 2) return false; $parts = explode('.', (string)$token);
-
reporter My temporary solution is to just disable the hook that runs this code from ext_localconf.php:
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp']['nnrestapi']);
-
- changed status to closed
Fixed in nnhelpers 2.0.4
- Log in to comment