class SamlService in SAML Authentication 8
Same name and namespace in other branches
- 8.3 src/SamlService.php \Drupal\samlauth\SamlService
- 8.2 src/SamlService.php \Drupal\samlauth\SamlService
- 4.x src/SamlService.php \Drupal\samlauth\SamlService
Class SamlService.
@package Drupal\samlauth
Hierarchy
- class \Drupal\samlauth\SamlService implements ContainerInjectionInterface
Expanded class hierarchy of SamlService
1 file declares its use of SamlService
- SamlController.php in src/
Controller/ SamlController.php - Contains Drupal\samlauth\Controller\SamlController.
1 string reference to 'SamlService'
1 service uses SamlService
File
- src/
SamlService.php, line 20 - Contains Drupal\samlauth\SamlService.
Namespace
Drupal\samlauthView source
class SamlService implements ContainerInjectionInterface {
/**
* @var \OneLogin_Saml2_Auth
*/
protected $auth;
/**
* Constructor for Drupal\samlauth\SamlService.
*
* @param \OneLogin_Saml2_Auth $auth
*/
public function __construct(OneLogin_Saml2_Auth $auth) {
$this->auth = $auth;
}
/**
* Factory method for dependency injection container.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @return static
*/
public static function create(ContainerInterface $container) {
$config = samlauth_get_config();
$auth = new OneLogin_Saml2_Auth($config);
return new static($auth);
}
/**
* Show metadata about the local sp. Use this to configure your saml2 IDP
*
* @return mixed xml string representing metadata
* @throws InvalidArgumentException
*/
public function getMetadata() {
$settings = $this->auth
->getSettings();
$metadata = $settings
->getSPMetadata();
$errors = $settings
->validateMetadata($metadata);
if (empty($errors)) {
return $metadata;
}
else {
throw new InvalidArgumentException('Invalid SP metadata: ' . implode(', ', $errors), OneLogin_Saml2_Error::METADATA_SP_INVALID);
}
}
/**
* Initiate a SAML2 authentication flow.
*
* @param string $return_to
* The path to return the user to after a successful login.
*/
public function login($return_to = null) {
$this->auth
->login($return_to);
}
/**
* Initiate a SAML2 logout flow.
*
* @param null $return_to
* The path to return the user to after a successful login.
*/
public function logout($return_to = null) {
user_logout();
$this->auth
->logout($return_to, array(
'referrer' => $return_to,
));
}
/**
* Process a SAML response (assertion consumer service)
*
* @return array|null
* Returns array with error description on error. Null otherwise.
* @throws \OneLogin_Saml2_Error
*/
public function acs() {
$this->auth
->processResponse();
$errors = $this->auth
->getErrors();
if (!empty($errors)) {
return $errors;
}
if (!$this
->isAuthenticated()) {
return array(
'error' => 'Could not authenticate.',
);
}
}
// Helper function.
public function getData() {
return $this->auth
->getAttributes();
}
/**
* @return bool if a valid user was fetched from the saml assertion this request.
*/
protected function isAuthenticated() {
return $this->auth
->isAuthenticated();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SamlService:: |
protected | property | ||
SamlService:: |
public | function | Process a SAML response (assertion consumer service) | |
SamlService:: |
public static | function |
Factory method for dependency injection container. Overrides ContainerInjectionInterface:: |
|
SamlService:: |
public | function | ||
SamlService:: |
public | function | Show metadata about the local sp. Use this to configure your saml2 IDP | |
SamlService:: |
protected | function | ||
SamlService:: |
public | function | Initiate a SAML2 authentication flow. | |
SamlService:: |
public | function | Initiate a SAML2 logout flow. | |
SamlService:: |
public | function | Constructor for Drupal\samlauth\SamlService. |