diff --git a/README.md b/README.md index 649cf5b8..bad57d54 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,14 @@ type Profile = { * `decryptionPvk`: optional private key that will be used to attempt to decrypt any encrypted assertions that are received * `signatureAlgorithm`: optionally set the signature algorithm for signing requests, valid values are 'sha1' (default), 'sha256', or 'sha512' * `digestAlgorithm`: optionally set the digest algorithm used to provide a digest for the signed data object, valid values are 'sha1' (default), 'sha256', or 'sha512' - * `xmlSignatureTransforms`: optionally set an array of signature transforms to be used in HTTP-POST signatures. By default this is `[ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#' ]` + * `xmlSignatureTransforms`: optionally set an array of signature transforms to be used in HTTP-POST signatures. By + default this is `[ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#' ]` + * `attrValueMapper`: optionally set a function that maps attributes values into plain strings. By default this is: + ```js + attrValueMapper = function (value) { + return typeof value === 'string' ? value : value._; + }; + ``` * **Additional SAML behaviors** * `additionalParams`: dictionary of additional query params to add to all requests; if an object with this key is passed to `authenticate`, the dictionary of additional query params will be appended to those present on the returned URL, overriding any specified by initialization options' additional parameters (`additionalParams`, `additionalAuthorizeParams`, and `additionalLogoutParams`) * `additionalAuthorizeParams`: dictionary of additional query params to add to 'authorize' requests diff --git a/lib/passport-saml/saml.js b/lib/passport-saml/saml.js index 519d22ae..7c7c30a2 100644 --- a/lib/passport-saml/saml.js +++ b/lib/passport-saml/saml.js @@ -80,6 +80,12 @@ SAML.prototype.initialize = function (options) { options.signatureAlgorithm = 'sha1'; } + if(!options.attrValueMapper) { + options.attrValueMapper = function (value) { + return typeof value === 'string' ? value : value._; + }; + } + /** * List of possible values: * - exact : Assertion context must exactly match a context in the list @@ -1008,9 +1014,7 @@ SAML.prototype.processValidlySignedAssertion = function(xml, samlResponseXml, in .map(attr => attr.Attribute) ); - var attrValueMapper = function(value) { - return typeof value === 'string' ? value : value._; - }; + var attrValueMapper = this.options.attrValueMapper; if (attributes) { attributes.forEach(attribute => {