Skip to content

Laravel API Authentication Comparison This repository demonstrates and compares three popular authentication methods in Laravel for building secure APIs: Sanctum Passport JWT (tymon/jwt-auth)

Notifications You must be signed in to change notification settings

akram-khodami/laravel-auth-showcase

Repository files navigation

Laravel Logo

laravel-auth-showcase

Laravel API Authentication Comparison

This repository demonstrates and compares three popular authentication methods in Laravel for building secure APIs:

  • Sanctum
  • Passport
  • JWT (tymon/jwt-auth)

Purpose

The goal of this project is to practice, implement, and evaluate different authentication methods available in Laravel. Each method is developed in a separate Git branch for clarity and easy comparison.

This project serves as a learning opportunity and showcases my ability to:

  • Work with Laravel 12 and modern tools
  • Implement secure and RESTful authentication APIs
  • Handle JSON-based request validation and error responses
  • Follow best practices for structuring Laravel API projects

Branches

Each branch represents one method of authentication:

  • sanctum-auth — Laravel Sanctum implementation
  • passport-auth — Laravel Passport implementation
  • jwt-auth — JWT (tymon/jwt-auth) implementation

Features

  • Basic user CRUD operations:
    • Create a new user
    • View all users
    • View a specific user
    • Update user
    • Delete user
  • Server-side validation with JSON error responses
  • Token-based authentication (per method)
  • Clean, modular code
  • Comments and documentation in code

Tools Used

  • Laravel 12
  • Composer
  • Git & Git branches
  • Laravel Sanctum / Passport / JWT
  • PHP 8.2+

Getting Started

  1. Clone the repository and switch to the desired branch:
git clone https://github.com/akram-khodami/laravel-auth-showcase.git
cd laravel-auth-showcase
git checkout sanctum-auth # or passport-auth / jwt-auth
  1. Install dependencies:
composer install
  1. Set up your .env file:
- php artisan key:generate
+ cp .env.example .env
+ php artisan key:generate
  1. Set up your database:
  • Create a new MySQL (or other) database, e.g. laravel_auth_showcase
  • Open .env file and update the following:
DB_DATABASE=laravel_auth_showcase
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password
  1. Run migrations:
php artisan migrate
  1. Seed test data(Optional) :
php artisan db:seed
  1. Start the development server:
php artisan serve
  1. If you are working with the auth-passport branch, make sure to run the following commands to generate a personal access client and clear the cache:
php artisan passport:client --personal
php artisan cache:clear

License

This project is open-source and available under the MIT license.
Feel free to fork, contribute, or use it as a base for your own Laravel API projects.

About

Laravel API Authentication Comparison This repository demonstrates and compares three popular authentication methods in Laravel for building secure APIs: Sanctum Passport JWT (tymon/jwt-auth)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages