PHPCas composer package and Codeigniter 3

534 views Asked by At

I am trying to make a Codeigniter 3 application to authenticate to a CAS server. I installed the phpcas package with composer but I cant find any details or examples on how to do this. I want the access to this application to be only from authentication users.

I believe that I have to edit a config file but I cant find any to write down the cas server url, etc. Also, in the controller of the page, I have to call somehow the library but I need some example for that.

So the main question is how can i get to use phpcas inside my controller methods amd how to configure it?

I created a controller and have inside:

?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class AuthController extends CI_Controller {

public function actionLogin()
{
    $this->module->casService->forceAuthentication();
    $username = $this->module->casService->getUsername();
    $this->module->casService->getAttribute('mail')
    $this->module->casService->getAttribute('title')=='TEACHER';
    //$auth->assign($casRole, $user->id);    
    
}

public function actionLogout()
{
    $this->module->casService->logout(Url::home(true));
    // In case the logout fails (not authenticated)
    return $this->redirect(Url::home(true));
}

}
1

There are 1 answers

0
Christos Pras On

I place to the controller file the line:

require_once(APPPATH . '/../vendor/autoload.php');

and I init with:

$phpCAS = new phpCAS;
phpCAS::client(CAS_VERSION_2_0, 'sso-test.sch.gr', 443, '', false);