# Class 'Middleware\\Authorization' not found

**URL:** <https://discourse.slimframework.com/t/class-middleware-authorization-not-found/3317>\
**Category:** Questions\
**Created:** [August 6, 2019, 12:48am UTC](https://discourse.slimframework.com/t/class-middleware-authorization-not-found/3317 "2019-08-06T00:48:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leelz914](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@leelz914](https://discourse.slimframework.com/u/leelz914)\
**Post date:** [August 6, 2019, 12:48am UTC](https://discourse.slimframework.com/t/class-middleware-authorization-not-found/3317/1 "2019-08-06T00:48:55Z")

</div>

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:

> **[maurobonfietti/rest-api-slim-php](https://github.com/maurobonfietti/rest-api-slim-php)**
>
> Example of REST API with Slim PHP Framework. Contribute to maurobonfietti/rest-api-slim-php development by creating an account on GitHub.

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

> **[chadicus/slim-oauth2-middleware](https://github.com/chadicus/slim-oauth2-middleware)**
>
> Middleware for Using OAuth2 within a Slim Framework API - chadicus/slim-oauth2-middleware

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 ☹

Can someone please point me in the right direction?

Thank you,

-Leelz

---

<div class="post-metadata">

**Author:** ![leelz914](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@leelz914](https://discourse.slimframework.com/u/leelz914)\
**Post date:** [August 6, 2019, 1:21am UTC](https://discourse.slimframework.com/t/class-middleware-authorization-not-found/3317/2 "2019-08-06T01:21:59Z")

</div>

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!
