CAS authentication on Yii2

Hello,

I tried to implement CAS Authentication on Yii 2, but it seems I can’t do it with the IdentityInterface.

Maybe I didn’t understand well, but it seems that in order to manipulate the User class correctly, you have to implement the IdentityInterface.

However, you have to implement for exemple the method findIdentity($id).

With a CAS authentication, I have no means to get information by passing the $id argument.

Indeed, when you want to authenticate, you are redirected to a CAS page, and there you pass the login and password, and the CAS server decides if you are authenticated or not.

So, I can’t find nor provide Identity for a given $id.

How is it possible to make a CAS authentication with Yii 2, by using the User possibilities? (I want to use the Autorization features with the RBAC for example, I need the User feature.)

Judging from the results of my Google search, no one has implemented CAS in Yii2 yet. Or, if they have, they haven’t shared.

You ever get anywhere on this? My current project need CAS auth. Specifically it needs to auth against Jasig CAS 3.5.

You can add jasig/phpcas via composer.

Then use the phpCAS functions to authenticate. I configured my CAS information in config/params, then replaced the SiteController->actionLogin function with:




// Enable debugging

        \phpCAS::setDebug();


        // Initialize phpCAS

        \phpCAS::client(CAS_VERSION_2_0, \Yii::$app->params['casHost'], \Yii::$app->params['casPort'], \Yii::$app->params['casContext']);

        \phpCAS::setNoCasServerValidation();

        \phpCAS::forceAuthentication();

        echo \phpCAS::getUser();



So, when I log in, it echo’s my username out.

Now to expand that into something useful…