poofe/yii2-cas-client

CAS authentication for Yii2

Installs: 19

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 3

Open Issues: 2

Type:yii2-extension

1.0.0 2018-07-25 03:24 UTC

This package is not auto-updated.

Last update: 2024-04-28 04:37:22 UTC


README

Yii2 library for authentication by CAS, using the library phpCAS.

Usage

  1. Add this to the project with composer require poofe/yii2casclient

  2. Configure the Yii2 application, e.g. in backend/config/main.php :

    return [
        ...
        'session' => [
            'class' => 'poofe\yii2casclient\cas\Session',
            ...
        ],
        'modules' => [
            'cas' => [
                'class' => 'poofe\yii2casclient\cas\CasModule',
                'config' => [
                    'host' => 'ssoserver.example.com',
                    'port' => '443',
                    'path' => '/idp/profile/cas',
                    // optional parameters
                    'certfile' => false, // empty, or path to a SSL cert, or false to ignore certs
                    'debug' => true, // will add many logs into X/runtime/logs/cas.log
                ],
            ],
    
  3. Add actions that use this CAS module, e.g. in SiteController :

    public function actionLogin()
    {
        if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        return $this->redirect(['/cas/auth/login']);
    }
    
    public function actionLogout()
    {
        if (Yii::$app->user->isGuest) {
            return $this->redirect(['/cas/auth/logout']);
        }
        return $this->goHome();
    }
    

Notes

The user component that implements yii\web\IdentityInterface will be used to fetch the local profile after querying the CAS server. It means that if User is the App component and CAS returns a username of "bibendum", the authentication will be successful if and only if the result of User::findIdentity("bibendum") is not null.

The action path '/cas/auth/login' starts with the alias of the module, as defined in the application configuration, e.g. 'cas' in 'modules' => [ 'cas' => [ ... ] ].