Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FATAL: Trying to include an un existing class #1244

Closed
itay-moav opened this issue Aug 18, 2021 · 7 comments
Closed

FATAL: Trying to include an un existing class #1244

itay-moav opened this issue Aug 18, 2021 · 7 comments

Comments

@itay-moav
Copy link

In file src/AuthorizationValidators/BearerTokenValidator.php
You have the following code

        $this->jwtConfiguration->setValidationConstraints(
            \class_exists(StrictValidAt::class)
                ? new StrictValidAt(new SystemClock(new DateTimeZone(\date_default_timezone_get())))
                : new ValidAt(new SystemClock(new DateTimeZone(\date_default_timezone_get()))),
            new SignedWith(
                new Sha256(),
                InMemory::plainText($this->publicKey->getKeyContents(), $this->publicKey->getPassPhrase() ?? '')
            )
        );

Notice the \class_exists condition which is done on StrictValidAt::class This can not work. You need the class StrictValidAt to exist for this to work.... which would make this condition moot.
You must use a simple string syntax there. Autoloader will try to include and fail at that line

**[Wed Aug 18 12:24:56.175459 2021] [php7:warn] [pid 5674:tid 140327830636288] [client 127.0.0.1:41668] PHP Warning: include_once(Lcobucci/JWT/Validation/Constraint/StrictValidAt.php): failed to open stream: No such file or directory in **

@eugene-borovov
Copy link
Contributor

Could you describe your setup? I cannot reproduce this issue. Do you use custom class autoloading?

@itay-moav
Copy link
Author

itay-moav commented Aug 19, 2021 via email

@eugene-borovov
Copy link
Contributor

Class constant works with unknown class https://3v4l.org/kEpZH
\class_exists has second parameter for control autoloading. I tested this code with PHP 7.2 and error reporting E_ALL and I didn`t get the warning.

@itay-moav
Copy link
Author

itay-moav commented Aug 19, 2021 via email

@eugene-borovov
Copy link
Contributor

I suggest to use PSR-0 autoloading for legacy code.

@itay-moav
Copy link
Author

itay-moav commented Aug 20, 2021 via email

@Sephster
Copy link
Member

Thanks for reporting this @itay-moav and thanks to @eugene-borovov for his investigations. I think given Eugene's findings, it is unlikely we would work around this issue as it seems to be more a user-implementation issue rather than anything wrong with this library's code or use of PHP syntax.

If I am wrong with this I'd be happy to re-open this issue and take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants