0

I am trying to integrate firebase/php-jwt into my Laravel project.

I added the following code from the firebase/php-jwt to test it out.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Client;
use GuzzleHttp;
use Phpfastcache\CacheManager;
use Firebase\JWT\CachedKeySet;
use Firebase\JWT\JWT;


class MyUserController extends Controller
{

    public function searchUser(Request $request)
    {

        $jwksUri = 'omitted';

        // Create an HTTP client (can be any PSR-7 compatible HTTP client)
        $httpClient = new Client();

        // Create an HTTP request factory (can be any PSR-17 compatible HTTP request factory)
        $httpFactory = new GuzzleHttp\Psr7\HttpFactory();

        // Create a cache item pool (can be any PSR-6 compatible cache item pool)
        $cacheItemPool = CacheManager::getInstance('files');

        $keySet = new CachedKeySet(
            $jwksUri,
            $httpClient,
            $httpFactory,
            $cacheItemPool,
            null, // $expiresAfter int seconds to set the JWKS to expire
            true  // $rateLimit    true to enable rate limit of 10 RPS on lookup of invalid keys
        );


        $decoded = JWT::decode($jwt, $keySet);

        $token = $request->bearerToken();
        dd($token);

    }


}

But I am getting the following error when I run the code Class 'Firebase\JWT\CachedKeySet' not found

I found a similar question here and I have tried adding the require statement for vendor/autoload.php and it didn't work for me.

I am using PHP version 7.4.29.

Here is my composer.json

{
    "name": "laravel/lumen",
    "description": "The Laravel Lumen Framework.",
    "keywords": ["framework", "laravel", "lumen"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.3|^8.0",
        "firebase/php-jwt": "^6.1",
        "flipbox/lumen-generator": "^8.2",
        "guzzlehttp/guzzle": "^7.0",
        "itsgoingd/clockwork": "^5.1",
        "laravel/lumen-framework": "^8.3.1",
        "phpfastcache/phpfastcache": "^8.1",
        "symfony/psr-http-message-bridge": "^2.1"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "phpunit/phpunit": "^9.5.10"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ]
    },
    "symfony/psr-http-message-bridge": "0.2"
}

So how do I fix this?

Charlie
  • 3,113
  • 3
  • 38
  • 60
  • What version of `firebase/php-jwt` are you using. Because the `CachedKeySet` feature only got implemented 11 days ago. – geertjanknapen May 09 '22 at 07:33
  • `firebase/php-jwt` v6.1.2 – Charlie May 09 '22 at 07:51
  • @geertjanknapen yeah that explains it. But it is already in the docs in the homepage of the github repo so I was under the impression `CachedKeySet ` was released – Charlie May 09 '22 at 14:06
  • Yeah at first it seemed like that aswell, turns out `v6.1.2` was released 18 days ago and `CachedKeySet` only got added 11 days ago, so I suppose it's being implemented right now. – geertjanknapen May 09 '22 at 14:10

0 Answers0