-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
158 lines (151 loc) · 5.51 KB
/
config.js
File metadata and controls
158 lines (151 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const SimpleProfileMapper = require('./lib/simpleProfileMapper');
const { dedent, prettyPrintXml } = require('./lib/utils/string-utils');
const { resolveFilePath } = require('./lib/utils/file-utils');
const Parser = require('xmldom').DOMParser;
const chalk = require('chalk');
const fs = require('fs');
function certFileCoercer(value) {
const filePath = resolveFilePath(value);
if (filePath) {
return fs.readFileSync(filePath)
}
throw new Error(
chalk`{red Invalid / missing {bold key/cert}} - {yellow not a valid crypt key/cert or file path}}`
)
}
const metadata = [{
id: "IDO",
optional: false,
displayName: 'Saml ID',
description: 'Le samlID de l‘élève',
multiValue: false
}, {
id: "PRE",
optional: false,
displayName: 'Prénom',
description: 'Le prénom de l‘élève',
multiValue: false
}, {
id: "NOM",
optional: true,
displayName: 'Nom',
description: 'Le nom de l‘élève',
multiValue: false
}];
const profileMapper = SimpleProfileMapper.fromMetadata(metadata);
module.exports = (function() {
const config = {
host: process.env.HOST || 'localhost',
port: process.env.PORT || 7654,
https: {
enableHttps: process.env.HTTPS || false,
httpsPrivateKey: process.env.HTTPS_PRIVATE_KEY,
httpsCert: process.env.HTTPS_CERT,
},
rollSession: process.env.ROLL_SESSION || false,
authentication: {
secret: process.env.AUTH_SECRET,
},
readOnlyMode: process.env.READ_ONLY_MODE || false,
profile: {
userName: 'saml.jackson@example.com',
nameIdFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
IDO: 'SamlID',
PRE: 'Saml',
NOM: 'Jackson',
},
metadata,
IDP_PATHS: {
SSO: '/saml/sso',
SLO: '/saml/slo',
METADATA: '/metadata',
SIGN_IN: '/signin',
SIGN_OUT: '/signout',
GENERATE: '/generate'
},
sp: {
url: process.env.SP_URL || 'http://localhost:4200',
paths: {
metadata: '/api/saml/metadata.xml',
assert: '/api/saml/assert',
login: '/api/saml/login',
}
},
idpOptions: {
issuer: 'urn:example:idp',
signatureAlgorithm: 'rsa-sha256',
digestAlgorithm: 'sha256',
signResponse: true,
lifetimeInSeconds: 3600,
authnContextClassRef: 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport',
allowRequestAcsUrl: true,
serviceProviderId() { return `${config.sp.url}${config.sp.paths.metadata}` },
sloUrl: '',
acsUrl: () => { return `${config.sp.url}${config.sp.paths.assert}` },
audience: () => { return `${config.sp.url}${config.sp.paths.metadata}` },
relayState: () => { return `${config.sp.url}${config.sp.paths.login}` },
cert: certFileCoercer('./idp-public-cert.pem'),
key: certFileCoercer('./idp-private-key.pem'),
encryptAssertion: false,
encryptionCert: true,
encryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
keyEncryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
authnContextDecl: null,
includeAttributeNameFormat: true,
profileMapper,
postEndpointPath: () => { return `http://${config.host}:${config.port}${config.IDP_PATHS.SSO}` },
redirectEndpointPath: function() { return config.IDP_PATHS.SSO },
logoutEndpointPaths: {},
getUserFromRequest: function(req) { return req.user; },
getPostURL: function (audience, authnRequestDom, req, callback) {
return callback(null, req.idp.options.acsUrl);
},
transformAssertion: function(assertionDom) {
if (this.authnContextDecl) {
var declDoc;
try {
declDoc = new Parser().parseFromString(this.authnContextDecl);
} catch(err){
console.log('Unable to parse Authentication Context Declaration XML', err);
}
if (declDoc) {
const authnContextDeclEl = assertionDom.createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml:AuthnContextDecl');
authnContextDeclEl.appendChild(declDoc.documentElement);
const authnContextEl = assertionDom.getElementsByTagName('saml:AuthnContext')[0];
authnContextEl.appendChild(authnContextDeclEl);
}
}
},
responseHandler: function(response, opts, req, res) {
console.log(dedent(chalk`
Sending SAML Response to {cyan ${opts.postUrl}} =>
{bold RelayState} =>
{cyan ${opts.relayState || UNDEFINED_VALUE}}
{bold SAMLResponse} =>`
));
console.log(prettyPrintXml(response.toString(), 4));
res.render('samlresponse', {
AcsUrl: opts.postUrl,
SAMLResponse: response.toString('base64'),
RelayState: opts.RelayState
});
},
},
CRYPT_TYPES: {
certificate: /-----BEGIN CERTIFICATE-----[^-]*-----END CERTIFICATE-----/,
'RSA private key': /-----BEGIN RSA PRIVATE KEY-----\n[^-]*\n-----END RSA PRIVATE KEY-----/,
'public key': /-----BEGIN PUBLIC KEY-----\n[^-]*\n-----END PUBLIC KEY-----/,
},
CERT_OPTIONS: [
'cert',
'key',
'encryptionCert',
'encryptionPublicKey',
'httpsPrivateKey',
'httpsCert',
],
WILDCARD_ADDRESSES: ['0.0.0.0', '::'],
UNDEFINED_VALUE: 'None'
}
return config
})();