Integration Guide

Laravel

Complete guide for integrating Laravel applications with CAS SSO

2 min setup Easy Laravel 10 / 11+

1. Installation

Install the CAS client package via Composer:

Terminal
composer require cas-system/laravel-client

After installation, publish the configuration file:

php artisan vendor:publish --tag=cas-config

2. Configuration

Add the following variables to your .env file:

.env
CAS_SERVER_URL=https://your-cas-server.com
CAS_CLIENT_ID=your_client_id
CAS_CLIENT_SECRET=your_client_secret
CAS_CALLBACK_URL=https://your-app.com/cas/callback
config/cas-client.php
return [
    'server_url'      => env('CAS_SERVER_URL'),
    'client_id'       => env('CAS_CLIENT_ID'),
    'client_secret'   => env('CAS_CLIENT_SECRET'),
    'callback_url'    => env('CAS_CALLBACK_URL'),

    // Security
    'enable_signature_validation' => true,
    'verify_ssl'  => true,
    'timeout'     => 30,

    // Routes
    'routes' => [
        'enabled'    => true,
        'prefix'     => 'cas',
        'middleware'  => ['web'],
    ],

    // User management
    'user' => [
        'create_local_users' => true,
        'model' => 'App\Models\User',
    ],

    // Cache
    'cache' => [
        'enabled' => true,
        'ttl'     => 3600,
    ],
];

3. User Model Setup

Add the HasCasAuth trait to your User model:

app/Models/User.php
use CasSystem\Traits\HasCasAuth;

class User extends Authenticatable
{
    use HasCasAuth;

    protected $fillable = [
        'name', 'email', 'cas_id', 'cas_token',
    ];
}

4. Middleware & Routes

Register the CAS middleware in your application:

bootstrap/app.php (Laravel 11)
$middleware->alias([
    'cas.auth' => \CasSystem\Middleware\CasAuthenticate::class,
]);

Protect your routes:

routes/web.php
Route::middleware(['cas.auth'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::get('/profile',   [ProfileController::class, 'show']);
});

// CAS callback route (handled by the package if routes.enabled = true)
Route::get('/cas/callback', [CasController::class, 'callback']);

// Access the authenticated CAS user
$user = session('cas_user');
Done! Your Laravel application is now connected to CAS SSO. Users will be redirected to the CAS login page and returned to your app with an authenticated session.

Next Steps