Using SimpleSAML with Yii2


I’m wondering if anyone can help me with this problem. Basically i need to use SimpleSAML to enable SSO with one of our systems for one of our Yii2 based portals.

I have SimpleSAML set up and working ok, however the problem comes when trying to use it with Yii2. The SimpleSAML documentation states i should be doing the following to use it from my framework:

We start off with loading a file which registers the simpleSAMLphp classes with the autoloader.


We select our authentication source:

$as = new SimpleSAML_Auth_Simple('default-sp');

We then require authentication:


I assume that the problem is with the Yii autoloader clashing in some way, as i’ve read mention of this exact issue on old Yii being solved by unregistering the yii autoloader before using SimpleSAML, the registering it again.

This doesn’t seem a nice way of doing it, and in any case doesn’t seem to work with Yii2.

I’d appreciate any help or pointers on this!


Does anybody have any ideas on this one? Or even a pointer of what to be looking for getting the autoloader to work?

If you installed SimpleSAML via Composer, try to remove this line:


I’m not sure if it helps, but the _autoload.php file tries to include Composer’s autoload.php which is completely unnecessary in your case.

I managed to solve it, rather than a problem with the require, it was a problem with calling the function the correct way in Yii2, so using the example on the SimpleSAML website, within Yii2 add a slash to whichever function you need to use, as so:

$as = new \SimpleSAML_Auth_Simple('default-sp');