corbosman/laravel-passport-claims

Syntax error when generating new token

Closed this issue · 5 comments

I get following error when trying to generate new token:

Method CorBosman\Passport\AccessToken::__toString() must not throw an exception, caught ParseError: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Method CorBosman\\Passport\\AccessToken::__toString() must not throw an exception, caught ParseError: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' at /var/www/dev/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php:0)
[stacktrace]
#0 {main}
"} 

I use the following versions:

  • laravel/framework 8.77.1
  • laravel/passport 10.1.4
  • lcobucci/jwt 3.4.6
  • corbosman/laravel-passport-claims 3.0.1

I still run on PHP 7.3, so might that be the issue?

I'm not sure if 7.4 is the minimum requirement. The toString actually comes from the underlying laravel code. Are you sure any code you added yourself doesnt contain a typo? Maybe try a static analyses tool to check. Else maybe show a longer stacktrace so i can see what the method chain is that's called.

Thanks for your fast reply.

Turns out it's an issue with arrow function:

$formatters = array_map(fn ($formatter) => new $formatter, config('passport-claims.formatters', []));

Arrow functions were introduced in PHP 7.4 and we are still on 7.3. I'll look into if we can upgrade to 7.4, otherwise I'll fork it and change it.

I guess it would be nice to set minimum PHP version in Composer, totally trivial of course :)

I actually reverted back to a regular closure, try 3.0.2. Does that fix it for you?

Hmm, now I get the following error:

Method CorBosman\Passport\AccessToken::__toString() must not throw an exception, caught Error: Class 'Lcobucci\JWT\Encoding\ChainedFormatter' not found {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Method CorBosman\\Passport\\AccessToken::__toString() must not throw an exception, caught Error: Class 'Lcobucci\\JWT\\Encoding\\ChainedFormatter' not found at /var/www/gms/current/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php:0)
[stacktrace]
#0 {main}
"} 

Which is due to lcobucci/jwt version being 3.4. I could lock it to 4, but that requires PHP 7.4.

I have downgraded to v2 (specifically corbosman/laravel-passport-claims 2.0.1) and it seems to work perfectly fine. I guess I'll upgrade to v3 once we upgrade the PHP version.

Thank you for your help :) I will close this issue.

Hi, ok. No problems. There unfortunately are some version issues between all the moving parts of passport. The underlying JWT lib has been making changes that required quite extensive changes in Laravel and my package. Glad that 2.0 works for you.