Skip to Content
🎉 Bref 3.0 is released. Read more →
DocumentationLaravelLaravel Passport

Laravel Passport

Install Laravel Passport on your machine as explained in the Passport documentation . With Laravel 11 and later, run:

php artisan install:api --passport

This command generates the encryption keys in the storage/ directory and runs the migrations locally. On AWS Lambda, the keys must be deployed with the application, and the migrations and OAuth clients must be created in the production database:

Deploy the keys

The key files (storage/oauth-private.key and storage/oauth-public.key) must be deployed. The serverless.yml file generated for Laravel excludes the storage/ directory, include the keys in the package:

serverless.yml
package: patterns: # Exclude the 'storage' directory - '!storage/**' # Except the public and private keys required by Laravel Passport - 'storage/oauth-private.key' - 'storage/oauth-public.key'

The keys are not committed to git: if you deploy from CI, make them available there (you can generate them with php artisan passport:keys).

On Lambda, Bref moves the storage directory (storage_path()) to /tmp, so Passport does not find the keys at their default location. Load them from the deployed storage/ directory in AppServiceProvider::boot():

app/Providers/AppServiceProvider.php
use Laravel\Passport\Passport; public function boot(): void { Passport::loadKeysFrom(base_path('storage')); }

Deploy

You can now redeploy the application:

bref deploy

Run the migrations

Create the Passport tables in the production database:

bref command "migrate --force"

Create clients

Finally, create the OAuth clients your application needs, for example a personal access client:

bref command "passport:client --personal --name 'Laravel Personal Access Client'"

Since Passport 12, the password grant is disabled by default: to create a password grant client (passport:client --password), first call Passport::enablePasswordGrant() in AppServiceProvider::boot() and deploy.

Last updated on