1. Go to this page and download the library: Download asasmoyo/yii2-saml library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace app\controllers;
use Yii;
use yii\web\Controller;
use yii\helpers\Url;
class SamlController extends Controller {
// Remove CSRF protection
public $enableCsrfValidation = false;
public function actions() {
return [
'login' => [
'class' => 'asasmoyo\yii2saml\actions\LoginAction',
'returnTo' => Yii::app()->user->returnUrl
]
];
}
}
namespace app\controllers;
use Yii;
use yii\web\Controller;
use yii\helpers\Url;
class SamlController extends Controller {
// Remove CSRF protection
public $enableCsrfValidation = false;
public function actions() {
return [
...
'acs' => [
'class' => 'asasmoyo\yii2saml\actions\AcsAction',
'successCallback' => [$this, 'callback'],
'successUrl' => Url::to('site/welcome'),
]
];
}
/**
* @param array $param has 'attributes', 'nameId' , 'sessionIndex', 'nameIdNameQualifier' and 'nameIdSPNameQualifier' from response
*/
public function callback($param) {
// do something
//
// if (isset($_POST['RelayState'])) {
// $_POST['RelayState'] - should be returnUrl from login action
// }
}
}
public function actions() {
return [
...
'metadata' => [
'class' => 'asasmoyo\yii2saml\actions\MetadataAction'
]
];
}
$session = Yii::$app->session;
public function actions() {
return [
...
'logout' => [
'class' => 'asasmoyo\yii2saml\actions\LogoutAction',
'returnTo' => Url::to('site/bye'),
'parameters' => [],
'nameId' => $session->get('nameId'),
'sessionIndex' => $session->get('sessionIndex'),
'stay' => false,
'nameIdFormat' => null,
'nameIdNameQualifier' => $session->get('nameIdNameQualifier'),
'nameIdSPNameQualifier' => $session->get('nameIdSPNameQualifier'),
'logoutIdP' => false, // if you don't want to logout on idp
]
];
}
public function actions() {
...
return [
...
'sls' => [
'class' => 'asasmoyo\yii2saml\actions\SlsAction',
'successUrl' => Url::to('site/bye'),
'logoutIdP' => false, // if you don't want to logout on idp
]
]
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.