-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and fix nameidentifier parsing in case Format attribute is …
…there
- Loading branch information
Showing
9 changed files
with
178 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
exports.Strategy = require('./strategy'); | ||
exports.Strategy = require('./strategy'); | ||
exports.SAML = require('./saml'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"name": "passport-wsfed-saml2", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "WS-federation with SAML 2 and 1.1 tokens for Passport (used on Microsoft products like Windows Azure Active Directory / Access Control Service and ADFS).", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"author": { | ||
"name": "Matias Woloski", | ||
"email": "[email protected]", | ||
|
@@ -23,7 +26,11 @@ | |
}, | ||
"devDependencies": { | ||
"express": "2.5.x", | ||
"ejs": "0.7.x" | ||
"ejs": "0.7.x", | ||
"mocha": "*", | ||
"should": "~1.2.1", | ||
"moment": "~1.7.2", | ||
"saml": "~0.2.7" | ||
}, | ||
"engines": { | ||
"node": ">= 0.6.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var assert = require('assert'), | ||
fs = require('fs'), | ||
utils = require('./utils'), | ||
moment = require('moment'), | ||
should = require('should'), | ||
saml11 = require('saml').Saml11, | ||
SamlPassport = require('../lib/passport-wsfed-saml2/saml').SAML; | ||
|
||
describe('saml 1.1', function () { | ||
|
||
it('should parse attributes', function (done) { | ||
// cert created with: | ||
// openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem | ||
|
||
var options = { | ||
cert: fs.readFileSync(__dirname + '/test-auth0.pem'), | ||
key: fs.readFileSync(__dirname + '/test-auth0.key'), | ||
issuer: 'urn:issuer', | ||
lifetimeInSeconds: 600, | ||
audiences: 'urn:myapp', | ||
attributes: { | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': '[email protected]', | ||
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar' | ||
}, | ||
nameIdentifier: 'foo', | ||
nameIdentifierFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified' | ||
}; | ||
|
||
var signedAssertion = saml11.create(options); | ||
|
||
var publicKey = fs.readFileSync(__dirname + '/test-auth0.cer').toString(); | ||
var saml_passport = new SamlPassport({cert: publicKey, realm: 'urn:myapp'}); | ||
var profile = saml_passport.validateResponse(signedAssertion, function(error, profile) { | ||
|
||
assert.ok(profile); | ||
assert.equal('foo', profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier']); | ||
assert.equal('Foo Bar', profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name']); | ||
assert.equal('[email protected]', profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress']); | ||
assert.equal('[email protected]', profile['email']); | ||
assert.equal('urn:issuer', profile['issuer']); | ||
done(); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MIIEDzCCAvegAwIBAgIJALr9HwgrQ7GeMA0GCSqGSIb3DQEBBQUAMGIxGDAWBgNVBAMTD2F1dGgwLmF1dGgwLmNvbTESMBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZDAeFw0xMjEyMjkxNTMwNDdaFw0xMzAxMjgxNTMwNDdaMGIxGDAWBgNVBAMTD2F1dGgwLmF1dGgwLmNvbTESMBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMZiVmNHiXLldrgbS50ONNOH7pJ2zg6OcSMkYZGDZJbOZ/TqwauC6JOnI7+xtkPJsQHZSFJs4U0srjZKzDCmaz2jLAJDShP2jaXlrki16nDLPE//IGAg3BJguSmBCWpDbSm92V9hSsE+Mhx6bDaJiw8yQ+Q8iSm0aTQZtp6O4ICMu00ESdh9NJqIECELvP31ADV1Xhj7IbyyVPDFxMv3ol5BySE9wwwOFUq/wv7Xz9LRiUjUzPO+Lq3OM3o/uCDbk7jD7XrGUuOydALD8ULsXp4EuDO+nFbeXB/iKndZynuVKokirywl2nD2IP0/yncdLQZ8ByIyqP3G82fq/l8p7AsCAwEAAaOBxzCBxDAdBgNVHQ4EFgQUHI2rUXeBjTv1zAllaPGrHFcEK0YwgZQGA1UdIwSBjDCBiYAUHI2rUXeBjTv1zAllaPGrHFcEK0ahZqRkMGIxGDAWBgNVBAMTD2F1dGgwLmF1dGgwLmNvbTESMBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZIIJALr9HwgrQ7GeMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAFrXIhCy4T4eGrikb0R2wHv/uS548r3pZyBV0CDbcRwAtbnpJMvkGFqKVp4pmyoIDSVNK/j+sLEshB20XftezHZyRJbCUbtKvXQ6FsxoeZMlN0ITYKTaoBZKhUxxj90otAhNC58qwGUPqt2LewJhHyLucKkGJ1mQ3b5xKZ532ToufouH9VLhig3H1KnxWo/zMD6Ke8cCk6qO9htuhI06s3GQGS1QWQtAmm17C6TfKgDwQFZwhqHUUZnwKRH8gU6OgZsvhgV1B7H5mjZcu57KMiDBekU9MEY0DCVTN3WkmcTII668zLsJrkNX6PEfck1AMBbVE6pEUKcWwq3uaLvlAUo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEowIBAAKCAQEAxmJWY0eJcuV2uBtLnQ4004fuknbODo5xIyRhkYNkls5n9OrB | ||
q4Lok6cjv7G2Q8mxAdlIUmzhTSyuNkrMMKZrPaMsAkNKE/aNpeWuSLXqcMs8T/8g | ||
YCDcEmC5KYEJakNtKb3ZX2FKwT4yHHpsNomLDzJD5DyJKbRpNBm2no7ggIy7TQRJ | ||
2H00mogQIQu8/fUANXVeGPshvLJU8MXEy/eiXkHJIT3DDA4VSr/C/tfP0tGJSNTM | ||
874urc4zej+4INuTuMPtesZS47J0AsPxQuxengS4M76cVt5cH+Iqd1nKe5UqiSKv | ||
LCXacPYg/T/Kdx0tBnwHIjKo/cbzZ+r+XynsCwIDAQABAoIBAFPWWwu5v6x+rJ1B | ||
a8MDre93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Im5/C0WQ | ||
N2FpAoGBAOss6RN2krieqbn1mG8e2v5mMUd0CJkiJu2y5MnF3dYHXSQ3/ePAh/Yg | ||
JOthpgYgBh+mV0DLqJhx/1DLS/xiqcoHDlndQDmYbtvvY7RlMo00+nGzkRVOfrqy | ||
hC+1KsYHGPbSQixNQXtvFbAAVMSo+RRBkVGINYGDFnlQUpkppYRk | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIEDzCCAvegAwIBAgIJALr9HwgrQ7GeMA0GCSqGSIb3DQEBBQUAMGIxGDAWBgNV | ||
BAMTD2F1dGgwLmF1dGgwLmNvbTESMBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQG | ||
EwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZDAeFw0x | ||
MjEyMjkxNTMwNDdaFw0xMzAxMjgxNTMwNDdaMGIxGDAWBgNVBAMTD2F1dGgwLmF1 | ||
dGgwLmNvbTESMBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQGEwJVUzETMBEGA1UE | ||
CBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZDCCASIwDQYJKoZIhvcNAQEB | ||
BQADggEPADCCAQoCggEBAMZiVmNHiXLldrgbS50ONNOH7pJ2zg6OcSMkYZGDZJbO | ||
Z/TqwauC6JOnI7+xtkPJsQHZSFJs4U0srjZKzDCmaz2jLAJDShP2jaXlrki16nDL | ||
PE//IGAg3BJguSmBCWpDbSm92V9hSsE+Mhx6bDaJiw8yQ+Q8iSm0aTQZtp6O4ICM | ||
u00ESdh9NJqIECELvP31ADV1Xhj7IbyyVPDFxMv3ol5BySE9wwwOFUq/wv7Xz9LR | ||
iUjUzPO+Lq3OM3o/uCDbk7jD7XrGUuOydALD8ULsXp4EuDO+nFbeXB/iKndZynuV | ||
Kokirywl2nD2IP0/yncdLQZ8ByIyqP3G82fq/l8p7AsCAwEAAaOBxzCBxDAdBgNV | ||
HQ4EFgQUHI2rUXeBjTv1zAllaPGrHFcEK0YwgZQGA1UdIwSBjDCBiYAUHI2rUXeB | ||
jTv1zAllaPGrHFcEK0ahZqRkMGIxGDAWBgNVBAMTD2F1dGgwLmF1dGgwLmNvbTES | ||
MBAGA1UEChMJQXV0aDAgTExDMQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGlu | ||
Z3RvbjEQMA4GA1UEBxMHUmVkbW9uZIIJALr9HwgrQ7GeMAwGA1UdEwQFMAMBAf8w | ||
DQYJKoZIhvcNAQEFBQADggEBAFrXIhCy4T4eGrikb0R2wHv/uS548r3pZyBV0CDb | ||
cRwAtbnpJMvkGFqKVp4pmyoIDSVNK/j+sLEshB20XftezHZyRJbCUbtKvXQ6Fsxo | ||
eZMlN0ITYKTaoBZKhUxxj90otAhNC58qwGUPqt2LewJhHyLucKkGJ1mQ3b5xKZ53 | ||
2ToufouH9VLhig3H1KnxWo/zMD6Ke8cCk6qO9htuhI06s3GQGS1QWQtAmm17C6Tf | ||
KgDwQFZwhqHUUZnwKRH8gU6OgZsvhgV1B7H5mjZcu57KMiDBekU9MEY0DCVTN3Wk | ||
mcTII668zLsJrkNX6PEfck1AMBbVE6pEUKcWwq3uaLvlAUo= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var xmlCrypto = require('xml-crypto'), | ||
crypto = require('crypto'), | ||
xmldom = require('xmldom'); | ||
|
||
exports.isValidSignature = function(assertion, cert) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
var signature = xmlCrypto.xpath.SelectNodes(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; | ||
var sig = new xmlCrypto.SignedXml(null, { idAttribute: 'AssertionID' }); | ||
sig.keyInfoProvider = { | ||
getKeyInfo: function (key) { | ||
return "<X509Data></X509Data>"; | ||
}, | ||
getKey: function (keyInfo) { | ||
return cert; | ||
} | ||
}; | ||
sig.loadSignature(signature.toString()); | ||
return sig.checkSignature(assertion); | ||
}; | ||
|
||
exports.getIssuer = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement.getAttribute('Issuer'); | ||
}; | ||
|
||
exports.getAssertionID = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement.getAttribute('AssertionID'); | ||
}; | ||
|
||
exports.getIssueInstant = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement.getAttribute('IssueInstant'); | ||
}; | ||
|
||
exports.getConditions = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement.getElementsByTagName('saml:Conditions'); | ||
}; | ||
|
||
exports.getAudiences = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement | ||
.getElementsByTagName('saml:Conditions')[0] | ||
.getElementsByTagName('saml:AudienceRestrictionCondition')[0] | ||
.getElementsByTagName('saml:Audience'); | ||
}; | ||
|
||
exports.getAuthenticationStatement = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement | ||
.getElementsByTagName('saml:AuthenticationStatement')[0]; | ||
}; | ||
|
||
exports.getAttributes = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement | ||
.getElementsByTagName('saml:Attribute'); | ||
}; | ||
|
||
exports.getNameIdentifier = function(assertion) { | ||
var doc = new xmldom.DOMParser().parseFromString(assertion); | ||
return doc.documentElement | ||
.getElementsByTagName('saml:NameIdentifier')[0]; | ||
}; |