PHP code example of hanovate / cas

1. Go to this page and download the library: Download hanovate/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/ */

    

hanovate / cas example snippets

bash
$ ./artisan vendor:publish --tag=cas
Copied File [/vendor/hanovate/cas/src/config/config.php] To [/config/cas.php]
Publishing complete.

...
use Illuminate\Support\Facades\Auth;
use App\Auth\Guards\CasGuard;
...
    
    ...
    public function boot()
    {
        $this->registerPolicies();

        Auth::extend('cas',function($app, $name, array $config) {
            return new CasGuard();
        });

        Gate::define('request',function($user) {
            return true;
        });
    }

...

...

Route::get('/',function() {
    if (cas()->isAuthenticated()) {
        echo 'authenticated<br>'; 
        echo 'click here to go to <a href="'.route('main.home').'">home</a><br>';
        echo 'user: '.cas()->user().'<br>';
        echo '<a href="'.route('main.logout').'">logout</a>';
    } else {
        echo 'not authenticated<br>';
        echo '<a href="'.route('main.login').'">login</a>';
    }
});


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


Route::middleware(['cas.auth'])->group(function() {
    Route::get('/main', function() {
        echo 'This is a main home page<br>';
        echo 'user: '.cas()->user().'<br>';
        echo '<a href="'.route('main.logout').'">logout</a>';
    })->name('main.home');

    Route::get('/auth/logout',function() {
        return cas()->logout(null,'https://auth1.unm.edu/');
    })->name('main.logout');
});
...