PHPackages                             samuelcalegari/laravel-cas - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. samuelcalegari/laravel-cas

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

samuelcalegari/laravel-cas
==========================

Apereo CAS Authentication for Laravel

03PHP

Since Mar 20Pushed 1y agoCompare

[ Source](https://github.com/samuelcalegari/laravel-cas)[ Packagist](https://packagist.org/packages/samuelcalegari/laravel-cas)[ RSS](/packages/samuelcalegari-laravel-cas/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Apereo CAS Authentication for Laravel
=====================================

[](#apereo-cas-authentication-for-laravel)

Easy Bring to CAS Authentication for Laravel 9 and Apereo PhpCAS 1.6

Fork from

Install
-------

[](#install)

#### Via Composer

[](#via-composer)

```
$ composer require samuelcalegari/laravel-cas:@dev
```

#### Via edit `composer.json`

[](#via-edit-composerjson)

```
"require": {
...
    "samuelcalegari/laravel-cas": "@dev"
},

```

Next, update Composer from the Terminal:

```
$ composer update
```

Configuration
-------------

[](#configuration)

After updating composer, add the ServiceProvider to the providers array in `config/app.php`.

```
'providers' => array(
    .....
    Sentrasoft\Cas\CasServiceProvider::class,
);
```

Now add the alias in `config/app.php`.

```
'aliases' => array(
    ......
    'Cas' => Sentrasoft\Cas\Facades\Cas::class,
);
```

Add the middelware to your `Kernel.php` file or leverage your own:

```
'cas.auth'  => \Sentrasoft\Cas\Middleware\Authenticate::class,
'cas.guest' => \Sentrasoft\Cas\Middleware\RedirectIfAuthenticated::class,
```

Now publish the configuration `cas.php` file:

```
$ php artisan vendor:publish --provider="Sentrasoft\Cas\CasServiceProvider" --tag="config"
```

Add new environment variables below to your `.env`

```
CAS_HOSTNAME=cas.example.com
CAS_VALIDATION=https://cas.example.com/cas/p3/serviceValidate
CAS_VERSION=3.0
CAS_CONTROL_SESSIONS=true
CAS_LOGOUT_URL=https://cas.example.com/cas/logout
CAS_SERVICE_BASE_URL=http://127.0.0.1:8000

```

> To see further configuration, please see and read the description for each configuration item [config/cas.php](src/Config/cas.php)

Route
-----

[](#route)

#### Authentication

[](#authentication)

Redirect the user to the authentication page for the provider.

```
Route::get('/cas/login', function() {
    return cas()->authenticate();
})->name('cas.login');
```

#### Controller and Callback Route

[](#controller-and-callback-route)

You can create a new controller named `Auth\CasController`.

```
php artisan make:controller Auth\CasController
```

```
class CasController extends Controller
{
    /**
     * Obtain the user information from CAS.
     *
     * @return Illuminate\Http\RedirectResponse
     */
    public function callback()
    {
        // $username = Cas::getUser();
        // Here you can store the returned information in a local User model on your database (or storage).

        // This is particularly usefull in case of profile construction with roles and other details
        // e.g. Auth::login($local_user);

        return redirect()->route('home');
    }
}
```

When the authentication is performed the callback url is invoked. In that callback you can process the User and create a local entry in the database.

```
Route::get('/cas/callback', 'Auth\CasController@callback')->name('cas.callback');
```

#### Logout

[](#logout)

Logout of the CAS Session and redirect users.

```
Route::post('/cas/logout', [ 'middleware' => 'cas.auth', function() {
    cas()->logout();

    // You can also add @param string $url in param[0]
    cas()->logout(url('/'));

    // Or add @param string $service in param[1]
    cas()->logout('', url('/'));

}])->name('cas.logout');
```

> The `cas.auth` middleware is optional, but you will need to handle the error when a user tries to logout when they do not have a CAS Session.

> If the `CAS_LOGOUT_REDIRECT` configuration item in `.env` is added, the value is taken from that configuration. Or if nothing is configured, the value is taken based on the value you specified.

If you want to use *SLO (Single Logout)* (if the CAS server supports SLO), Your application must have a valid SSL and the CAS server must be able to send *HTTP POST* `/cas/logout` without having to verify `CsrfToken`. Therefore, you must change the `App\Http\Middleware\VerifyCsrfToken` file and exclude `/cas/logout` route.

```
/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
protected $except = [
    //

    '/cas/logout',
];
```

You can check that it works by trying to send an *HTTP POST* via [cURL](https://en.wikipedia.org/wiki/CURL).

```
curl -X POST https://yourapp.com/cas/logout

```

Usage
-----

[](#usage)

#### Get User

[](#get-user)

To retrieve authenticated credentials.

> Not ID (integer), but given on the CAS login (username) form.

```
$uid = Cas::user()->id;
```

#### Get User Attributes

[](#get-user-attributes)

Get the attributes for for the currently connected user.

```
foreach (Cas::user()->getAttributes() as $key => $value) {
	...
}
```

#### Get User Attribute

[](#get-user-attribute)

Retrieve a specific attribute by key name. The attribute returned can be either a string or an array based on matches.

```
$value = Cas::user()->getAttribute('key');
```

Help us to keep making awesome stuff. You don't have to be a developer to support our open source work. If you want to receive personal support, or just feel all warm and fuzzy inside from helping open source development, donations are very welcome. Thank you.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 53.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6546e601a7f928401281d5cffbe763b79acd06e2882e0ddfacea02185d032576?d=identicon)[samuelcalegari](/maintainers/samuelcalegari)

---

Top Contributors

[![falestra](https://avatars.githubusercontent.com/u/12063138?v=4)](https://github.com/falestra "falestra (8 commits)")[![samuelcalegari](https://avatars.githubusercontent.com/u/15143054?v=4)](https://github.com/samuelcalegari "samuelcalegari (5 commits)")[![shimeche](https://avatars.githubusercontent.com/u/1849666?v=4)](https://github.com/shimeche "shimeche (2 commits)")

### Embed Badge

![Health badge](/badges/samuelcalegari-laravel-cas/health.svg)

```
[![Health](https://phpackages.com/badges/samuelcalegari-laravel-cas/health.svg)](https://phpackages.com/packages/samuelcalegari-laravel-cas)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
