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

Fixing NameID value mapping #246

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand Down