eggplantSword's avatar

Invalid key supplied only in certains routes

I'm trying to test out some api routes and I keep getting this error but it's strange because if I copy the route and move it, it works.

This is the first part of the error, it's over 300 lines total I'll add the rest if it's important

	"message": "Invalid key supplied",
	"exception": "LogicException",
	"file": "/var/www/btl-visor-new/vendor/league/oauth2-server/src/CryptKey.php",
	"line": 67,
	"trace": [
{
			"file": "/var/www/btl-visor-new/vendor/laravel/passport/src/PassportServiceProvider.php",
			"line": 275,
			"function": "__construct",
			"class": "League\OAuth2\Server\CryptKey",
			"type": "->"
		},
		{
			"file": "/var/www/btl-visor-new/vendor/laravel/passport/src/PassportServiceProvider.php",
			"line": 256,
			"function": "makeCryptKey",
			"class": "Laravel\Passport\PassportServiceProvider",
			"type": "->"
		},{...}
]

Routes

Route::middleware('api')->prefix('api')->group(function () {

//this works
    Route::get('/refunds',  [PopHelperController::class, 'popRefunds']);
    Route::get('/history', [PopHelperController::class, 'popRefundsHistory']);

    Route::prefix('pop-helper')->group(function () {
        Route::prefix('refunds')->group(function () {
//these show that error
            Route::get('/',  [PopHelperController::class, 'popRefunds']);
            Route::get('/history', [PopHelperController::class, 'popRefundsHistory']);
            Route::get('/{id}/products', [PopHelperController::class, 'popRefundProducts']);
            Route::get('/{id}/objects',  [PopHelperController::class, 'popRefundObjects']);

            Route::post('/', [PopHelperController::class, 'postPopRefund']);
        });
    });
});

As far as I know I'm not using Passport on these routes, in my kernal the api middleware only has 'throttle:100', \Illuminate\Routing\Middleware\SubstituteBindings::class,

I can still test it but I would like to use the actual route structure too, why am I getting this error on those routes?

0 likes
16 replies
wachaabi98's avatar

did you find a solution to that , i'm facing the same problem

dawnydawn's avatar

try this?

php artisan passport:install
2 likes
Hierro59's avatar

@dawnydawn This solution worked perfectly for me. My problem was that when trying to register a user through the API, I had that error, which I solved by running the command and finishing the installation and configuration of Laravel Passport.

2 likes
Vzm's avatar

I am receiving the same error on production , but everything is fine in local.any solution???

1 like
SahibKhan's avatar

I am getting this error on user->createToken('Api Token')

1 like
devcooljoe's avatar

@SahibKhan It seems people don't respond to issues like this. I really need this solution because I'm stuck right now.

devcooljoe's avatar

I'm having this same issue and I even tried to structure it like the poster here but what he said even managed to work for him is not working for me. The main issue behind the error now is this code "$user->createToken('authToken')->accessToken" or the "auth:api" middleware.

sandaruwan's avatar

To solve this add public key and private key to storage directory

2 likes
kurtobando's avatar

@pabloes have you tried php artisan passport:keys, these will generate the public and private keys in storage directory.

3 likes
ahmdsaza's avatar

I had try all solutions but it doesn't work :( I try all passport commands and generate keys a lot of times but not working, if someone know another way please help me. ( I try to deploy it in Heroku and I do all commands in production )

thangnm's avatar

It's very likely that in the User class, you use Laravel\Passport\HasApiTokens trait. If it's the case, change it to use Laravel\Sanctum\HasApiTokens;

Please or to participate in this conversation.