Skip to content

Commit 62f6eeb

Browse files
Replaces saml-idp with @node-saml/node-saml
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
1 parent 4e6e71e commit 62f6eeb

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"husky": "^8.0.0",
3737
"jose": "^5.2.4",
3838
"minimist": "^1.2.8",
39-
"saml-idp": "^1.2.1",
39+
"@node-saml/node-saml": "^5.0.1",
4040
"selfsigned": "^2.0.1"
4141
},
4242
"dependencies": {

test/jest_integration/runIdpServer.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,61 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
const { runServer } = require('saml-idp');
17-
16+
const express = require('express');
17+
const bodyParser = require('body-parser');
18+
const minimist = require('minimist');
1819
const { generate } = require('selfsigned');
20+
const { SAML } = require('@node-saml/node-saml');
1921

20-
const minimist = require('minimist');
22+
const argv = minimist(process.argv.slice(2), {
23+
default: { basePath: '' },
24+
});
2125

22-
const pems = generate(null, {
26+
const pems = generate([{ name: 'commonName', value: 'Test Identity Provider' }], {
2327
keySize: 2048,
2428
clientCertificateCN: '/C=US/ST=California/L=San Francisco/O=JankyCo/CN=Test Identity Provider',
2529
days: 7300,
2630
});
2731

28-
const argv = minimist(process.argv.slice(2), {
29-
default: { basePath: '' },
32+
// configure the SAML client (Service Provider)
33+
const saml = new SAML({
34+
// Dashboards SAML ACS URL
35+
callbackUrl: `http://localhost:5601${argv.basePath}/_opendistro/_security/saml/acs`,
36+
// the IdP redirect endpoint (you’ll register this SP with them ahead of time)
37+
entryPoint: 'https://your-idp.example.com/saml2/idp/SSOService.php',
38+
// the SP entityID (Audience URI)
39+
issuer: 'https://localhost:9200',
40+
// SP signing key & cert
41+
privateKey: pems.private.toString(),
42+
publicCert: pems.cert,
43+
// validate the IdP’s signature on the Response
44+
idpCert: pems.cert,
45+
audience: 'https://localhost:9200',
46+
skipRequestCompression: true,
3047
});
3148

32-
// Create certificate pair on the fly and pass it to runServer
33-
runServer({
34-
acsUrl: `http://localhost:5601${argv.basePath}/_opendistro/_security/saml/acs`,
35-
audience: 'https://localhost:9200',
36-
cert: pems.cert,
37-
key: pems.private.toString().replace(/\r\n/, '\n'),
49+
const app = express();
50+
app.use(bodyParser.urlencoded({ extended: false }));
51+
52+
// Initiate SSO by redirecting the browser to the IdP
53+
app.get('/login', (req, res, next) => {
54+
saml.getAuthorizeUrl(req, (err, url) => {
55+
if (err) return next(err);
56+
res.redirect(url);
57+
});
58+
});
59+
60+
// Consume the SAMLResponse at ACS endpoint
61+
app.post(`/_opendistro/_security/saml/acs`, (req, res, next) => {
62+
const { SAMLResponse, RelayState } = req.body;
63+
saml.validatePostResponse({ SAMLResponse, RelayState }, (err, profile, logout) => {
64+
if (err) return next(err);
65+
res.send(`SAML login successful for ${profile.nameID}`);
66+
});
67+
});
68+
69+
const port = 5601;
70+
app.listen(port, () => {
71+
console.log(`SAML SP listening on http://localhost:${port}`);
3872
});
73+

0 commit comments

Comments
 (0)