PHP code example of sentrasoft / laravel-cas

1. Go to this page and download the library: Download sentrasoft/laravel-cas library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sentrasoft / laravel-cas example snippets


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

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

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

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

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');
    }
}

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

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 URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
protected $except = [
    //

    '/cas/logout',
];

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

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

$value = Cas::user()->getAttribute('key');
 php
$ composer 
 php
$ php artisan vendor:publish --provider="Sentrasoft\Cas\CasServiceProvider" --tag="config"