2017 © Pedro PelĂĄez
 

yii2-extension yii2-auth-cas

CAS authentication for Yii2

image

silecs/yii2-auth-cas

CAS authentication for Yii2

  • Wednesday, March 21, 2018
  • by mytskine
  • Repository
  • 3 Watchers
  • 0 Stars
  • 111 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

yii2-auth-cas

Yii2 library for authentication by CAS, using the library phpCAS., (*1)

Usage

  1. Add this to the project with composer require silecs/yii2-auth-cas, (*2)

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

    return [
        ...
        'modules' => [
            'cas' => [
                'class' => 'silecs\yii2auth\cas\CasModule',
                'config' => [
                    'host' => 'ssoserver.example.com',
                    'port' => '443',
                    'path' => '/idp/profile/cas',
                    // optional parameters
                    'certfile' => '', // 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 :, (*4)

    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., (*5)

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' => [ ... ] ]., (*6)

Testing with a CAS container

Here are some instructions on deploying a Docker CAS server to test this library. This procedure will use the CAS interface of a Shibboleth instance. This was tested on Debian Stretch and Buster (testing)., (*7)

  1. Install docker from the extra repository at docker.io (I had errors with the older docker from the official Debian repository)., (*8)

  2. Install docker-compose either from Debian or docker.io., (*9)

  3. Git clone https://hub.docker.com/r/unicon/shibboleth-idp/ If using an old docker-compose, then chekout 3c29f10 because later commits require a too recent feature., (*10)

  4. Modify docker-compose.yml so that the container won't try to use the port 80, so replace "80:80" with "8080:80"., (*11)

  5. If your local Yii2 application is not using HTTPS, modify idp/shibboleth-idp/conf/cas-protocol.xml to replace c:regex="https://idptestbed/.*" by c:regex="https?://idptestbed/.*"., (*12)

  6. Add 127.0.0.1 idptestbed to /etc/hosts, as root., (*13)

  7. Configure your Yii2 application to use:, (*14)

    'host' => 'idptestbed',
    'port' => '443',
    'path' => '/idp/profile/cas',
    'certfile' => false,
    'debug' => true,
  8. Start the containers:, (*15)

    docker-compose build
    docker-compose run
  9. Go to the login page of your Yii2 app., (*16)

  10. Ctrl-C in the containers termainal to end them., (*17)

You can modify ldap/users.ldif if you want to add users to the CAS. Don't forget to rebuild the Docker images after this., (*18)

The Versions

21/03 2018

dev-master

9999999-dev

CAS authentication for Yii2

  Sources   Download

MIT

The Requires

 

by François Gannaz

authentication yii2 yii cas

21/03 2018

1.0.3

1.0.3.0

CAS authentication for Yii2

  Sources   Download

MIT

The Requires

 

by François Gannaz

authentication yii2 yii cas

08/12 2017

1.0.2

1.0.2.0

CAS authentication for Yii2

  Sources   Download

MIT

The Requires

 

by François Gannaz

authentication yii2 yii cas

10/10 2017

1.0.1

1.0.1.0

CAS authentication for Yii2

  Sources   Download

MIT

The Requires

 

by François Gannaz

authentication yii cas