Class 'Middleware\Authorization' not found

I am getting the following error:

2019/08/06 00:34:09 [error] 13986#13986: *3095 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Class 'Middleware\Authorization' not found in /home/user/api/app/middleware.php:5
Stack trace:
#0 /home/user/api/app/app.php(13): require()
#1 /home/user/api/public/index.php(3): require('/home/user/api/...')
#2 {main}
  thrown in /home/user/api/app/middleware.php on line 5" while reading response header from upstream, client: 47.21.236.22, server: api.domain.com, request: "GET /v1/playlists/user2 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "api.domain.com"

I started the project with this skeleton:

I installed this OAuth2 middleware (as per instructions: composer require, etc.):

I pasted the following code to app/data/dependencies.php:

use Chadicus\Slim\OAuth2\Middleware;
use OAuth2\Storage;
use OAuth2\GrantType;
$storage = new Storage\Memory(
    [
        'client_credentials' => [
            'page-web' => [
                'client_id' => pagewebu',
                'client_secret' => 'abcdef123',
                'scope' => 'apiUser',
            ],
        ],
    ]
);
$server = new OAuth2\Server( $storage, [ 'access_lifetime' => 3600 ], [ new GrantType\ClientCredentials($storage) ]);

I appended the following code to app/data/middleware.php:
$authMiddleware = new Middleware\Authorization($server, $app->getContainer());

It seems that something is not loading somewhere but everything checks out. I don’t even know what else to check. I think I’ve done everything: composer dump-autoload, removing vendor dir and installing everything with composer… all to no avail :frowning:

Can someone please point me in the right direction?

Thank you,

-Leelz

I hate it when I post about an issue and then fix it right after. This is what happened here.

I placed the use statements in the wrong file. I assumed that if I put the use in the dependencies.php it would be available to any other files included after it in the parent file app.php – which, in retrospect, makes no sense.

So, for anyone stumbling upon this post, please check where you’re calling the use Path\To\Package\Namspace parts and where you’re actually calling the functions.

Thanks!