DEV Community

Debajyoti Das
Debajyoti Das

Posted on

Laravel 9 & Passport for creating a basic OAuth2 implementation

Execute composer require laravel/passport
Execute php artisan migrate
Execute php artisan passport:install
Execute composer require laravel/breeze --dev
Execute php artisan breeze:install

Replace HasApiToken in Users with Sanctum/HasApiToken
Image description

Add api in auth array in the guard.php file
Image description

Execute php artisan passport:client
generate the client id, client name, callback, client secret

create an user through localhost:8000/register

Open Postman:
First Authorize user by sending a GET request, below image provided for reference:

Image description

Take the full url and search using the browser
Login then click Authorize
Now 404 not found page will be shown along with the code and state in url bar

Copy the code

Next process is to Generate the Bearer/Access token for accessing API's, take the below image for reference

Image description

Lastly for testing an API, the below example's been given:

Image description

Lastly, Passport's OAuth default routes:

Image description

Top comments (0)