Application Program Interfaces, APIs, are snippets of code that allow one software application to talk to another, providing a common language. Whether allowing seamless experiences for end users across multiple applications, or allowing data from one application to be fed into another, APIs have revolutionised in the last years.
If you are a beginner and you are learning and figuring out how to make apis and secure them, then you came to the right place, in this article i will show you how to set up an api authentication.
What is passport ?
Laravel Passport is a full OAuth2 server implementation, it was built to make it easy to apply authentication over an API for Laravel passport with password grant tokens based web applications.
After setting up laravel and installing composer please follow the following steps:
1- Install Passport via the Composer package manager:
composer require laravel/passport
the passport package will register its own database migrations.
2- Migrate the passport tables:
php artisan migrate
3- Install passport:
php artisan passport:install
This command will create the encryption keys needed to generate secure access tokens.
4- Configuring passport:
add the Laravel\Passport\HasApiTokens trait to your App\Usermodel.