Laravel Custom Response Messages from Passport Oauth2 Server
This sample project is meant to help beginners struggling with setting up Oauth2 server in laravel. It's using Laravel's official Oauth2 Passport package for this purpose. Another reason why this project is important is the customization of messages from passport and laravel in order to have a standard format for all the reponses sent back to the client. The test login credentials for the applications are:
Username: [email protected]
Password: a
Steps to install and run
All the commands down below should be run in project's root directory
- Clone the repository by running the following command
git clone https://github.com/ismail17719/Laravel-Passport-With-Custom-Response-Messages.git
- Open the terminal and go to the project root directory
- Run the composer command to install all dependencies
composer install
- Open .env.example and save it as .env file in the same root directory
- Open .env file and change the following database details
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=YOURDATABASE
DB_USERNAME=USERNAME
DB_PASSWORD=PASSWORD
- Run the following command to generate a unique for the application
php artisan key:generate
- Next we need to build the database. In order to do that run the following command in terminal. Let the process complete
php artisan migrate --seed
- To get the client id and secret run this command. Please, use Client ID: 2. that's the password grant client that we need.
php artisan passport:install
- Passport needs encryption keys to generate access tokens. To generate encryption keys for Passprot run the following commmand
php artisan passport:keys
- Congrats!! You are done. Everything else is done for. Now checkout the routes/api.php route file to see and test different routes. You can make http requests using something like Postman or Insomnia.
💥 💥 💥