Laravel 12 WorkOS AuthKit Authentication

Authentication is a crucial part of modern web applications, and WorkOS AuthKit provides a seamless way to integrate authentication, including SSO (Single Sign-On), into Laravel 12.

In this tutorial, I'll show you how to set up WorkOS AuthKit authentication in Laravel 12, configure your application, and implement login functionality using WorkOS.

By the end of this guide, you’ll have a working authentication system using WorkOS AuthKit in Laravel 12.

Using WorkOS as your authentication provider requires a WorkOS account. WorkOS offers free authentication for applications up to 1 million monthly active users.

WorkOS AuthKit Provides List of Authentication Options:

  • Social authentication (Google, Microsoft, GitHub, and Apple)
  • Passkey authentication
  • Email based "Magic Auth"
  • SSO

WorkOS AuthKit Authentication Laravel 12

Laravel 12 WorkOS AuthKit Authentication

 

Step 1: Install Laravel 12

To use WorkOS AuthKit as your application's authentication provider, select the WorkOS option when creating your new starter kit powered application via:

laravel new

WorkOS Install

laravel-12-authkit-install

 

Step 2: Configure WorkOS in Laravel

Update your env file with your WorkOS API credentials:

WORKOS_CLIENT_ID=client_XXXXXXXXX
WORKOS_API_KEY=sk_test_XXXXXXXXX
WORKOS_REDIRECT_URL="http://localhost:8000/authenticate"

 

Step 3: Configure Redirects in WorkOS

In Redirects Menu, update the Redirect URI in Sign-in callbackYour app homepage URL, and Logout redirect URL.

http://localhost:8000/authenticate

 

Step 4: Configuring AuthKit Authentication Methods

In the Authentication Menu, when using a WorkOS powered starter kit, we recommend that you disable "Email + Password" authentication within your application's WorkOS AuthKit configuration settings, allowing users to only authenticate via social authentication providers, passkeys, Magic Auth, and SSO.

This allows your application to avoid handling user passwords.

Note: Also, set up User Management in the Overview tab.

 

Step 5: Configuring AuthKit Session Timeouts

In addition, we recommend that you configure your WorkOS AuthKit session inactivity timeout to match your Laravel application's configured session timeout threshold.

laravel-12-authkit-session

 

Step 6: Run the Application

 Now, start your Laravel server:

php artisan serve

Login Page:

laravel-12-social-login-workos-authkit

Dashboard:

laravel-12-social-login-dashboard

List of Users:

workos-authkit-login-users-list

 


You might also like:

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS