SAML authentication module for ZF2.
This module uses onelogin/php-saml
internally and wrap the function in services.
Just require mehr-als-nix/zf-saml
in your composer.json
.
Enable it in application.config.php
'modules' => array (
// ---8<---
'ZF\ApiProblem',
'ZF\ContentNegotiation',
'MehrAlsNix\ZF\SAML',
// --->8---
),
Copy saml.local.php.dist
to config/autoload/saml.local.php
Provides an instance of OneLogin_Saml2_Auth
Provides an instance of OneLogin_Saml2_AuthnRequest
Provides an instance of OneLogin_Saml2_Metadata
Provides an instance of OneLogin_Saml2_Response
Provides an instance of OneLogin_Saml2_Settings
Assume $this->samlAuth
contains an instance of OneLogin_Saml2_Auth
, then
you would be able to protect your API.
if (!$this->samlAuth->isAuthenticated()) {
$this->getResponse()->setStatusCode(401);
return;
}