@@ -98,6 +98,13 @@ has 'cert' => (isa => 'Str', is => 'ro', required => 1);
9898has ' key' => (isa => ' Str' , is => ' ro' , required => 1);
9999has ' cacert' => (isa => ' Maybe[Str]' , is => ' ro' , required => 1);
100100
101+ has ' error_url' => (isa => ' Str' , is => ' ro' , required => 1);
102+ has ' slo_url_soap' => (isa => ' Str' , is => ' ro' , required => 1);
103+ has ' slo_url_redirect' => (isa => ' Str' , is => ' ro' , required => 1);
104+ has ' slo_url_post' => (isa => ' Str' , is => ' ro' , required => 1);
105+ has ' acs_url_post' => (isa => ' Str' , is => ' ro' , required => 1);
106+ has ' acs_url_artifact' => (isa => ' Str' , is => ' ro' , required => 1);
107+
101108has ' org_name' => (isa => ' Str' , is => ' ro' , required => 1);
102109has ' org_display_name' => (isa => ' Str' , is => ' ro' , required => 1);
103110has ' org_contact' => (isa => ' Str' , is => ' ro' , required => 1);
@@ -304,20 +311,23 @@ Returns the metadata XML document for this SP.
304311sub metadata {
305312 my ($self ) = @_ ;
306313
314+ use Net::SAML2::Util qw/ generate_id/ ;
315+
307316 my $x = XML::Generator-> new(' :pretty' , conformance => ' loose' );
308317 my $md = [' md' => ' urn:oasis:names:tc:SAML:2.0:metadata' ];
309318 my $ds = [' ds' => ' http://www.w3.org/2000/09/xmldsig#' ];
310319
311- $x -> EntityDescriptor(
320+ my $metadata = $x -> EntityDescriptor(
312321 $md ,
313322 {
314323 entityID => $self -> id },
315324 $x -> SPSSODescriptor(
316325 $md ,
317326 { AuthnRequestsSigned => defined ($self -> authnreq_signed) ? $self -> authnreq_signed : ' 1' ,
318327 WantAssertionsSigned => defined ($self -> want_assertions_signed) ? $self -> want_assertions_signed : ' 1' ,
319- errorURL => $self -> url . ' /saml/error' ,
320- protocolSupportEnumeration => ' urn:oasis:names:tc:SAML:2.0:protocol' },
328+ errorURL => $self -> url . $self -> error_url,
329+ protocolSupportEnumeration => ' urn:oasis:names:tc:SAML:2.0:protocol' ,
330+ ID => generate_id()},
321331 $x -> KeyDescriptor(
322332 $md ,
323333 {
@@ -336,29 +346,29 @@ sub metadata {
336346 $x -> SingleLogoutService(
337347 $md ,
338348 { Binding => ' urn:oasis:names:tc:SAML:2.0:bindings:SOAP' ,
339- Location => $self -> url . ' /saml/slo-soap ' },
349+ Location => $self -> url . $self -> slo_url_soap },
340350 ),
341351 $x -> SingleLogoutService(
342352 $md ,
343353 { Binding => ' urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect' ,
344- Location => $self -> url . ' /saml/sls-redirect-response ' },
354+ Location => $self -> url . $self -> slo_url_redirect },
345355 ),
346356 $x -> SingleLogoutService(
347357 $md ,
348358 { Binding => ' urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' ,
349- Location => $self -> url . ' /saml/sls-post-response ' },
359+ Location => $self -> url . $self -> slo_url_post },
350360 ),
351361 $x -> AssertionConsumerService(
352362 $md ,
353363 { Binding => ' urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' ,
354- Location => $self -> url . ' /saml/consumer-post ' ,
364+ Location => $self -> url . $self -> acs_url_post ,
355365 index => ' 1' ,
356366 isDefault => ' true' },
357367 ),
358368 $x -> AssertionConsumerService(
359369 $md ,
360370 { Binding => ' urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact' ,
361- Location => $self -> url . ' /saml/consumer-artifact ' ,
371+ Location => $self -> url . $self -> acs_url_artifact ,
362372 index => ' 2' ,
363373 isDefault => ' false' },
364374 ),
@@ -398,6 +408,21 @@ sub metadata {
398408 ),
399409 )
400410 );
411+
412+ use Net::SAML2::XML::Sig;
413+
414+ my $signer = Net::SAML2::XML::Sig-> new({
415+ key => $self -> key,
416+ cert => $self -> cert,
417+ sig_hash => ' sha256' ,
418+ digest_hash => ' sha256' ,
419+ x509 => 1,
420+ });
421+
422+ # create a signature
423+ my $signed = $signer -> sign($metadata );
424+
425+ return $signed ;
401426}
402427
403428__PACKAGE__ -> meta-> make_immutable;
0 commit comments