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

Correctly parse Attributes with multiple AttributeValues as arrays of strings #27

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions saml_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,23 @@ SAML.prototype.validateResponse = function(samlResponse, relayState, callback) {
}
if (attributes) {
for (let i = 0; i < attributes.length; i++) {
const value = attributes[i].getElementsByTagNameNS('urn:oasis:names:tc:SAML:2.0:assertion', 'AttributeValue')[0];
const values = attributes[i].getElementsByTagNameNS('urn:oasis:names:tc:SAML:2.0:assertion', 'AttributeValue');

let value;
if (values.length === 1) {
value = values[0].textContent;
} else {
value = [];
for (var attributeValue of values) {
value.push(attributeValue.textContent);
}
}

if (Meteor.settings.debug) {
console.log("Name: " + attributes[i]);
console.log(`Adding attrinute from SAML response to profile:` + attributes[i].getAttribute('Name') + " = " + value.textContent);
console.log(`Adding attribute from SAML response to profile:` + attributes[i].getAttribute('Name') + " = " + value);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you're using 'value' vs 'value.textContent'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of multiple attribute values, where "value" is an array, "value.textContent" will be undefined. Logging "value" should work whether it is a string or an array.

profile[attributes[i].getAttribute('Name')] = value.textContent;
profile[attributes[i].getAttribute('Name')] = value;

}
} else {
Expand Down