'What causes the Class not found error in this Laravel 8 API?

I am working on a Laravel 8 API. I use Auth0 for user registration and login. I need the user's id returned by Auth0 to use in my own application.

For this purpose I have the code, I have installed Guzzle with composer require guzzlehttp/guzzle:^7.0.

In routes\api.php I have the following:

// Public routes
Route::get('/authorization', [AuthController::class, 'authorization']);

// Protected routes
Route::group(['middleware' => ['jwt']], function () {
  Route::get('/user', [UserController::class, 'getUserId']);
});

In the AuthController I have:

class AuthController extends Controller{
  
    protected $appDomain;
    protected $appClientId;
    protected $appClientSecret;
    protected $appAudience;
    
    protected function authorization(){

        $this->appDomain = 'https://' . config('laravel-auth0.domain');
        $this->appClientId = config('laravel-auth0.client_id');
        $this->appClientSecret = config('laravel-auth0.client_secret');
        $this->appAudience = config('laravel-auth0.api_identifier');

        $client = new \GuzzleHttp\Client;

        try {
            $client = new \GuzzleHttp\Client();
            $response = $client->request('POST', $this->appDomain . '/oauth/token', [
                'form_params' => [
                        "client_id" =>        $this->appClientId,
                        "client_secret" =>    $this->appClientSecret,
                        "audience" =>         $this->appAudience,
                        "grant_type" =>       "client_credentials"
                ]
            ]);
        
            $response = json_decode($response->getBody());
        }
        catch (\GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
        }

        return $response;

    }
}

In the UserController I have:

namespace App\Http\Controllers;
use App\Http\Controllers\AuthController;
use Illuminate\Http\Request;

class UserController extends AuthController {

    // More code

    public function getUserId(){

    $access_token = parent::authorization()->access_token;

    $client = new \GuzzleHttp\Client;
        try {
              $client = new \GuzzleHttp\Client(['headers' => [
                 'authorization' => 'Bearer' . $access_token,
                 'content-type' => 'application/json'
               ]]);
                
              $response = $client->request('GET', $this->appDomain . '/userinfo');

              $response = json_decode($response->getBody());
        }
        catch (\GuzzleHttp\Exception\ClientException $e) {
                $response = $e->getResponse();
        }

        return  $response;
    }

    // More code
}

The problem

Using dd($access_token) does return a valid token. Yet, I get this error in Postman:

Error: Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found in \vendor\laravel\framework\src\Illuminate\Routing\Router.php 

Question

Where is my mistake?

UPDATE

As adviced in the comments, I run composer require symfony/psr-http-message-bridge and composer require nyholm/psr7.

But getUserId now returns Unauthorized.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source