Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

How to generate api key for Laravel Restful Api

I am using Laravel Passport for Authentication in my Laravel-8 Restful Api.

Route::group([
    'middleware' => 'auth:api'
], function () {
    Route::post('notices/pause', 'NoticeController@pause');
    Route::get('notices/read', 'NoticeController@read');
    Route::resource('notices', 'NoticeController', ['only' => ['index', 'show', 'store', 'update', 'destroy']]);
   });

I consume the endpoint in Angular. So far everything is working fine. However, I realise that I might need to send the endpoints to other users as external api.

How do I create api-key along with the restful api in Laravel-8?

Thanks.

0 likes
1 reply
fylzero's avatar

@noblemfd I don't believe Passport handles this out-of-the-box. I know Sanctum does.

See: https://laravel.com/docs/8.x/passport#passport-or-sanctum

Since oauth is a bit more complex than simply creating a bearer token, it is sort of expected that you will only create grant tokens as an authorized user of the system.

If you absolutely must do this, you might be able to hack something together using a client credentials grant token but I'm not entirely sure what the implications of that might be.

https://laravel.com/docs/8.x/passport#client-credentials-grant-tokens

1 like

Please or to participate in this conversation.