Added the ability to auto-load config from metadata url

This commit is contained in:
Dan Brown 2019-11-17 14:44:26 +00:00
parent 3a17ba2cb9
commit 488325f459
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 12 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use BookStack\Exceptions\SamlException;
use Illuminate\Support\Str;
use OneLogin\Saml2\Auth;
use OneLogin\Saml2\Error;
use OneLogin\Saml2\IdPMetadataParser;
/**
* Class Saml2Service
@ -103,6 +104,7 @@ class Saml2Service extends ExternalAuthService
/**
* Load the underlying Onelogin SAML2 toolkit.
* @throws \OneLogin\Saml2\Error
* @throws \Exception
*/
protected function getToolkit(): Auth
{
@ -113,8 +115,13 @@ class Saml2Service extends ExternalAuthService
$overrides = json_decode($overrides, true);
}
$metaDataSettings = [];
if ($this->config['autoload_from_metadata']) {
$metaDataSettings = IdPMetadataParser::parseRemoteXML($settings['idp']['entityId']);
}
$spSettings = $this->loadOneloginServiceProviderDetails();
$settings = array_replace_recursive($settings, $spSettings, $overrides);
$settings = array_replace_recursive($settings, $spSettings, $metaDataSettings, $overrides);
return new Auth($settings);
}

View File

@ -27,6 +27,9 @@ return [
// When syncing groups, remove any groups that no longer match. Otherwise sync only adds new groups.
'remove_from_groups' => env('SAML2_REMOVE_FROM_GROUPS', false),
// Autoload IDP details from the metadata endpoint
'autoload_from_metadata' => env('SAML2_AUTOLOAD_METADATA', false),
// Overrides, in JSON format, to the configuration passed to underlying onelogin library.
'onelogin_overrides' => env('SAML2_ONELOGIN_OVERRIDES', null),

View File

@ -22,6 +22,7 @@ class Saml2 extends TestCase
'saml2.onelogin.idp.entityId' => 'https://example.com/saml2/idp/metadata',
'saml2.onelogin.idp.singleSignOnService.url' => 'https://example.com/saml2/idp/sso',
'saml2.onelogin.idp.singleLogoutService.url' => 'https://example.com/saml2/idp/sls',
'saml2.autoload_from_metadata' => false,
'saml2.onelogin.idp.x509cert' => 'MIIEazCCAtOgAwIBAgIUe7a088Cnr4izmrnBEnx5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