11<?php
2-
2+
33/**
44 * Metadata lib of OneLogin PHP Toolkit
55 *
@@ -58,6 +58,7 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
5858 }
5959
6060 $ strOrganization = '' ;
61+
6162 if (!empty ($ organization )) {
6263 $ organizationInfoNames = array ();
6364 $ organizationInfoDisplaynames = array ();
@@ -96,6 +97,58 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
9697 $ strContacts = "\n" .implode ("\n" , $ contactsInfo );
9798 }
9899
100+ $ strAttributeConsumingService = '' ;
101+ if (isset ($ sp ['attributeConsumingService ' ])) {
102+ $ attrCsDesc = '' ;
103+ if (isset ($ sp ['attributeConsumingService ' ]['serviceDescription ' ])) {
104+ $ attrCsDesc = sprintf (
105+ ' <md:ServiceDescription xml:lang="en">%s</md:ServiceDescription> ' . PHP_EOL ,
106+ $ sp ['attributeConsumingService ' ]['serviceDescription ' ]
107+ );
108+ }
109+ if (!isset ($ sp ['attributeConsumingService ' ]['serviceName ' ])) {
110+ $ sp ['attributeConsumingService ' ]['serviceName ' ] = 'Service ' ;
111+ }
112+ $ requestedAttributeData = array ();
113+ foreach ($ sp ['attributeConsumingService ' ]['requestedAttributes ' ] as $ attribute ) {
114+ $ requestedAttributeStr = sprintf (' <md:RequestedAttribute Name="%s" ' , $ attribute ['name ' ]);
115+ if (isset ($ attribute ['nameFormat ' ])) {
116+ $ requestedAttributeStr .= sprintf (' NameFormat="%s" ' , $ attribute ['nameFormat ' ]);
117+ }
118+ if (isset ($ attribute ['friendlyName ' ])) {
119+ $ requestedAttributeStr .= sprintf (' FriendlyName="%s" ' , $ attribute ['friendlyName ' ]);
120+ }
121+ if (isset ($ attribute ['isRequired ' ])) {
122+ $ requestedAttributeStr .= sprintf (' isRequired="%s" ' , $ attribute ['isRequired ' ] === true ? 'true ' : 'false ' );
123+ }
124+ $ reqAttrAuxStr = " /> " ;
125+
126+ if (isset ($ attribute ['attributeValue ' ]) && !empty ($ attribute ['attributeValue ' ])) {
127+ $ reqAttrAuxStr = '> ' ;
128+ if (is_string ($ attribute ['attributeValue ' ])) {
129+ $ attribute ['attributeValue ' ] = array ($ attribute ['attributeValue ' ]);
130+ }
131+ foreach ($ attribute ['attributeValue ' ] as $ attrValue ) {
132+ $ reqAttrAuxStr .=<<<ATTRIBUTEVALUE
133+
134+ <saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> {$ attrValue }</saml:AttributeValue>
135+ ATTRIBUTEVALUE ;
136+ }
137+ $ reqAttrAuxStr .= "\n </md:RequestedAttribute> " ;
138+ }
139+
140+ $ requestedAttributeData [] = $ requestedAttributeStr . $ reqAttrAuxStr ;
141+ }
142+
143+ $ requestedAttributeStr = implode (PHP_EOL , $ requestedAttributeData );
144+ $ strAttributeConsumingService = <<<METADATA_TEMPLATE
145+ <md:AttributeConsumingService index="1">
146+ <md:ServiceName xml:lang="en"> {$ sp ['attributeConsumingService ' ]['serviceName ' ]}</md:ServiceName>
147+ {$ attrCsDesc }{$ requestedAttributeStr }
148+ </md:AttributeConsumingService>
149+ METADATA_TEMPLATE ;
150+ }
151+
99152 $ metadata = <<<METADATA_TEMPLATE
100153<?xml version="1.0"?>
101154<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
@@ -107,6 +160,7 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
107160 <md:AssertionConsumerService Binding=" {$ sp ['assertionConsumerService ' ]['binding ' ]}"
108161 Location=" {$ sp ['assertionConsumerService ' ]['url ' ]}"
109162 index="1" />
163+ {$ strAttributeConsumingService }
110164 </md:SPSSODescriptor> {$ strOrganization }{$ strContacts }
111165</md:EntityDescriptor>
112166METADATA_TEMPLATE ;
@@ -159,7 +213,7 @@ public static function addX509KeyDescriptors($metadata, $cert, $wantsEncrypted =
159213
160214 $ keyInfo = $ xml ->createElementNS (OneLogin_Saml2_Constants::NS_DS , 'ds:KeyInfo ' );
161215 $ keyInfo ->appendChild ($ keyData );
162-
216+
163217 $ keyDescriptor = $ xml ->createElementNS (OneLogin_Saml2_Constants::NS_MD , "md:KeyDescriptor " );
164218
165219 $ SPSSODescriptor = $ xml ->getElementsByTagName ('SPSSODescriptor ' )->item (0 );
0 commit comments