Centralizing Users For Multiple Laravel Apps Using SSO And Laravel Passport

Mark Caggiano
4 min readMar 22

Centralizing users for multiple Laravel apps can be achieved using a Single Sign-On (SSO) approach. This approach allows users to authenticate once and gain access to multiple applications without having to log in again. Here are the steps to centralize users for multiple Laravel apps using SSO:

Step 1: Create a new Laravel app for the Authentication Server

Create a new Laravel app that will serve as the authentication server. This app will handle the user authentication and authorization logic. You can create a new Laravel app by running the following command:

composer create-project --prefer-dist laravel/laravel auth-server

Step 2: Install and configure the Laravel Passport package

Laravel Passport is a package that allows you to create a full OAuth2 server implementation. This package will be used to handle authentication and authorization for the various applications. Install Laravel Passport using the following command:

composer require laravel/passport

After installing the package, you need to run the migration to create the necessary database tables:

php artisan migrate

Next, you need to run the passport:install command to create the encryption keys needed for secure access token generation:

php artisan passport:install

Step 3: Create the necessary API endpoints for user registration and login

Create the necessary API endpoints that will handle user registration and login. These endpoints will be used by the various applications to authenticate users. You can create these endpoints in the Laravel app you created in Step 1.
See Step 7 for this.

Step 4: Configure the Laravel Passport package

Open the auth-server/config/auth.php file and add the following lines to the ‘guards’ array:

'api' => [
'driver' => 'passport',
'provider' => 'users',
],
Mark Caggiano

Internet Marketer, Web Developer, Traveler