Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to exclude validUntil #569

Merged
merged 3 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Saml2/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class Metadata
* @param array $contacts Contacts info
* @param array $organization Organization ingo
* @param array $attributes
* @param bool $ignoreValidUntil exclude the validUntil tag from metadata
*
* @return string SAML Metadata XML
*/
public static function builder($sp, $authnsign = false, $wsign = false, $validUntil = null, $cacheDuration = null, $contacts = array(), $organization = array(), $attributes = array())
public static function builder($sp, $authnsign = false, $wsign = false, $validUntil = null, $cacheDuration = null, $contacts = array(), $organization = array(), $attributes = array(), $ignoreValidUntil = false)
{

if (!isset($validUntil)) {
Expand Down Expand Up @@ -173,7 +174,12 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
$metadata = <<<METADATA_TEMPLATE
<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="{$validUntilTime}"
METADATA_TEMPLATE;
$metadata = $metadata . "\n";
if ( $ignoreValidUntil === false ){
$metadata = $metadata . " validUntil=\"{$validUntilTime}\"\n";
}
$metadata = $metadata . <<<METADATA_TEMPLATE
cacheDuration="PT{$cacheDuration}S"
entityID="{$spEntityId}">
<md:SPSSODescriptor AuthnRequestsSigned="{$strAuthnsign}" WantAssertionsSigned="{$strWsign}" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
Expand Down
4 changes: 4 additions & 0 deletions tests/src/OneLogin/Saml2/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testBuilder()
$this->assertStringContainsString('<md:OrganizationName xml:lang="en-US">sp_test</md:OrganizationName>', $metadata);
$this->assertStringContainsString('<md:ContactPerson contactType="technical">', $metadata);
$this->assertStringContainsString('<md:GivenName>technical_name</md:GivenName>', $metadata);
$this->assertStringContainsString('validUntil', $metadata);

$security['authnRequestsSigned'] = true;
$security['wantAssertionsSigned'] = true;
Expand All @@ -66,6 +67,9 @@ public function testBuilder()

$this->assertStringNotContainsString('<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"', $metadata2);
$this->assertStringNotContainsString(' Location="http://stuff.com/endpoints/endpoints/sls.php"/>', $metadata2);

$metadata3 = Metadata::builder($spData, $security['authnRequestsSigned'], $security['wantAssertionsSigned'], null, null, $contacts, $organization, array(), true);
$this->assertStringNotContainsString('validUntil=', $metadata3);
}

/**
Expand Down