Added onelogin attribution and tweaks after testing saml with onelogin

This commit is contained in:
Dan Brown 2019-11-17 17:00:42 +00:00
parent 6d899f3b17
commit ebb3724892
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 9 additions and 10 deletions

View File

@ -83,10 +83,6 @@ class Saml2Service extends ExternalAuthService
*/ */
public function processAcsResponse(?string $requestId): ?User public function processAcsResponse(?string $requestId): ?User
{ {
if (is_null($requestId)) {
throw new SamlException(trans('errors.saml_invalid_response_id'));
}
$toolkit = $this->getToolkit(); $toolkit = $this->getToolkit();
$toolkit->processResponse($requestId); $toolkit->processResponse($requestId);
$errors = $toolkit->getErrors(); $errors = $toolkit->getErrors();
@ -251,17 +247,14 @@ class Saml2Service extends ExternalAuthService
/** /**
* Extract the details of a user from a SAML response. * Extract the details of a user from a SAML response.
* @throws SamlException
*/ */
public function getUserDetails(string $samlID, $samlAttributes): array public function getUserDetails(string $samlID, $samlAttributes): array
{ {
$emailAttr = $this->config['email_attribute']; $emailAttr = $this->config['email_attribute'];
$externalId = $this->getExternalId($samlAttributes, $samlID); $externalId = $this->getExternalId($samlAttributes, $samlID);
$email = $this->getSamlResponseAttribute($samlAttributes, $emailAttr, null);
if ($email === null) { $defaultEmail = filter_var($samlID, FILTER_VALIDATE_EMAIL) ? $samlID : null;
throw new SamlException(trans('errors.saml_no_email_address')); $email = $this->getSamlResponseAttribute($samlAttributes, $emailAttr, $defaultEmail);
}
return [ return [
'external_id' => $externalId, 'external_id' => $externalId,
@ -372,11 +365,16 @@ class Saml2Service extends ExternalAuthService
if ($this->config['dump_user_details']) { if ($this->config['dump_user_details']) {
throw new JsonDebugException([ throw new JsonDebugException([
'id_from_idp' => $samlID,
'attrs_from_idp' => $samlAttributes, 'attrs_from_idp' => $samlAttributes,
'attrs_after_parsing' => $userDetails, 'attrs_after_parsing' => $userDetails,
]); ]);
} }
if ($userDetails['email'] === null) {
throw new SamlException(trans('errors.saml_no_email_address'));
}
if ($isLoggedIn) { if ($isLoggedIn) {
throw new SamlException(trans('errors.saml_already_logged_in'), '/login'); throw new SamlException(trans('errors.saml_already_logged_in'), '/login');
} }

View File

@ -175,3 +175,4 @@ These are the great open-source projects used to help build BookStack:
* [WKHTMLtoPDF](http://wkhtmltopdf.org/index.html) * [WKHTMLtoPDF](http://wkhtmltopdf.org/index.html)
* [Draw.io](https://github.com/jgraph/drawio) * [Draw.io](https://github.com/jgraph/drawio)
* [Laravel Stats](https://github.com/stefanzweifel/laravel-stats) * [Laravel Stats](https://github.com/stefanzweifel/laravel-stats)
* [OneLogin's SAML PHP Toolkit](https://github.com/onelogin/php-saml)