samlesa 2.12.3 → 2.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of samlesa might be problematic. Click here for more details.
- package/build/index.js +54 -64
- package/build/index.js.map +1 -1
- package/build/src/api.js +24 -23
- package/build/src/api.js.map +1 -1
- package/build/src/binding-post.js +358 -368
- package/build/src/binding-post.js.map +1 -1
- package/build/src/binding-redirect.js +333 -332
- package/build/src/binding-redirect.js.map +1 -1
- package/build/src/binding-simplesign.js +222 -232
- package/build/src/binding-simplesign.js.map +1 -1
- package/build/src/entity-idp.js +132 -130
- package/build/src/entity-idp.js.map +1 -1
- package/build/src/entity-sp.js +96 -96
- package/build/src/entity-sp.js.map +1 -1
- package/build/src/entity.js +225 -235
- package/build/src/entity.js.map +1 -1
- package/build/src/extractor.js +369 -369
- package/build/src/extractor.js.map +1 -1
- package/build/src/flow.js +320 -319
- package/build/src/flow.js.map +1 -1
- package/build/src/libsaml.js +660 -641
- package/build/src/libsaml.js.map +1 -1
- package/build/src/metadata-idp.js +127 -127
- package/build/src/metadata-idp.js.map +1 -1
- package/build/src/metadata-sp.js +231 -231
- package/build/src/metadata-sp.js.map +1 -1
- package/build/src/metadata.js +166 -176
- package/build/src/metadata.js.map +1 -1
- package/build/src/types.js +11 -11
- package/build/src/urn.js +212 -212
- package/build/src/urn.js.map +1 -1
- package/build/src/utility.js +292 -248
- package/build/src/utility.js.map +1 -1
- package/build/src/validator.js +27 -26
- package/build/src/validator.js.map +1 -1
- package/index.d.ts +10 -10
- package/index.js +18 -18
- package/package.json +1 -5
- package/qodana.yaml +29 -29
- package/src/binding-post.ts +1 -1
- package/src/binding-redirect.ts +83 -64
- package/src/entity-idp.ts +26 -20
- package/src/libsaml.ts +79 -48
- package/src/utility.ts +147 -76
- package/types/index.d.ts +10 -10
- package/types/src/api.d.ts +13 -13
- package/types/src/binding-post.d.ts +46 -46
- package/types/src/binding-redirect.d.ts +52 -52
- package/types/src/binding-simplesign.d.ts +39 -39
- package/types/src/entity-idp.d.ts +35 -42
- package/types/src/entity-sp.d.ts +36 -36
- package/types/src/entity.d.ts +101 -99
- package/types/src/extractor.d.ts +25 -25
- package/types/src/flow.d.ts +6 -6
- package/types/src/libsaml.d.ts +200 -210
- package/types/src/metadata-idp.d.ts +24 -24
- package/types/src/metadata-sp.d.ts +36 -36
- package/types/src/metadata.d.ts +59 -57
- package/types/src/types.d.ts +129 -127
- package/types/src/urn.d.ts +194 -194
- package/types/src/utility.d.ts +134 -134
- package/types/src/validator.d.ts +3 -3
- package/.idea/compiler.xml +0 -6
- package/.idea/deployment.xml +0 -14
- package/.idea/jsLibraryMappings.xml +0 -6
- package/build/.idea/workspace.xml +0 -58
|
@@ -1,333 +1,334 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
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
|
-
* @private
|
|
52
|
-
* @desc
|
|
53
|
-
* @param {string}
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {
|
|
56
|
-
* @
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
* @
|
|
232
|
-
* @param {object}
|
|
233
|
-
* @param {
|
|
234
|
-
* @
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
* @
|
|
280
|
-
* @param {object}
|
|
281
|
-
* @param {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/**
|
|
30
|
+
* @file binding-redirect.ts
|
|
31
|
+
* @author tngan
|
|
32
|
+
* @desc Binding-level API, declare the functions using Redirect binding
|
|
33
|
+
*/
|
|
34
|
+
const utility_js_1 = __importStar(require("./utility.js"));
|
|
35
|
+
const libsaml_js_1 = __importDefault(require("./libsaml.js"));
|
|
36
|
+
const urn_js_1 = require("./urn.js");
|
|
37
|
+
const binding = urn_js_1.wording.binding;
|
|
38
|
+
const urlParams = urn_js_1.wording.urlParams;
|
|
39
|
+
/**
|
|
40
|
+
* @private
|
|
41
|
+
* @desc Helper of generating URL param/value pair
|
|
42
|
+
* @param {string} param key
|
|
43
|
+
* @param {string} value value of key
|
|
44
|
+
* @param {boolean} first determine whether the param is the starting one in order to add query header '?'
|
|
45
|
+
* @return {string}
|
|
46
|
+
*/
|
|
47
|
+
function pvPair(param, value, first) {
|
|
48
|
+
return (first === true ? '?' : '&') + param + '=' + value;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
* @desc Refractored part of URL generation for login/logout request
|
|
53
|
+
* @param {string} type
|
|
54
|
+
* @param {boolean} isSigned
|
|
55
|
+
* @param {string} rawSamlRequest
|
|
56
|
+
* @param {object} entitySetting
|
|
57
|
+
* @return {string}
|
|
58
|
+
*/
|
|
59
|
+
function buildRedirectURL(opts) {
|
|
60
|
+
const { baseUrl, type, isSigned, context, entitySetting, } = opts;
|
|
61
|
+
let { relayState = '' } = opts;
|
|
62
|
+
let noParams = true;
|
|
63
|
+
try {
|
|
64
|
+
noParams = new URL(baseUrl)?.searchParams?.size === 0;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
noParams = true;
|
|
68
|
+
}
|
|
69
|
+
const queryParam = libsaml_js_1.default.getQueryParamByType(type);
|
|
70
|
+
// In general, this xmlstring is required to do deflate -> base64 -> urlencode
|
|
71
|
+
const samlRequest = encodeURIComponent(utility_js_1.default.base64Encode(utility_js_1.default.deflateString(context)));
|
|
72
|
+
if (relayState !== '') {
|
|
73
|
+
relayState = pvPair(urlParams.relayState, encodeURIComponent(relayState));
|
|
74
|
+
}
|
|
75
|
+
if (isSigned) {
|
|
76
|
+
const sigAlg = pvPair(urlParams.sigAlg, encodeURIComponent(entitySetting.requestSignatureAlgorithm));
|
|
77
|
+
const octetString = samlRequest + relayState + sigAlg;
|
|
78
|
+
return baseUrl
|
|
79
|
+
+ pvPair(queryParam, octetString, noParams)
|
|
80
|
+
+ pvPair(urlParams.signature, encodeURIComponent(libsaml_js_1.default.constructMessageSignature(queryParam + '=' + octetString, entitySetting.privateKey, entitySetting.privateKeyPass, undefined, entitySetting.requestSignatureAlgorithm).toString()));
|
|
81
|
+
}
|
|
82
|
+
return baseUrl + pvPair(queryParam, samlRequest + relayState, noParams);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @desc Redirect URL for login request
|
|
86
|
+
* @param {object} entity object includes both idp and sp
|
|
87
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
88
|
+
* @return {string} redirect URL
|
|
89
|
+
*/
|
|
90
|
+
function loginRequestRedirectURL(entity, customTagReplacement) {
|
|
91
|
+
const metadata = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta };
|
|
92
|
+
const spSetting = entity.sp.entitySetting;
|
|
93
|
+
let id = '';
|
|
94
|
+
if (metadata && metadata.idp && metadata.sp) {
|
|
95
|
+
const base = metadata.idp.getSingleSignOnService(binding.redirect);
|
|
96
|
+
let rawSamlRequest;
|
|
97
|
+
if (spSetting.loginRequestTemplate && customTagReplacement) {
|
|
98
|
+
const info = customTagReplacement(spSetting.loginRequestTemplate);
|
|
99
|
+
id = (0, utility_js_1.get)(info, 'id', null);
|
|
100
|
+
rawSamlRequest = (0, utility_js_1.get)(info, 'context', null);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const nameIDFormat = spSetting.nameIDFormat;
|
|
104
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
105
|
+
id = spSetting.generateID();
|
|
106
|
+
rawSamlRequest = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLoginRequestTemplate.context, {
|
|
107
|
+
ID: id,
|
|
108
|
+
Destination: base,
|
|
109
|
+
Issuer: metadata.sp.getEntityID(),
|
|
110
|
+
IssueInstant: new Date().toISOString(),
|
|
111
|
+
NameIDFormat: selectedNameIDFormat,
|
|
112
|
+
AssertionConsumerServiceURL: metadata.sp.getAssertionConsumerService(binding.post),
|
|
113
|
+
EntityID: metadata.sp.getEntityID(),
|
|
114
|
+
AllowCreate: spSetting.allowCreate,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
id,
|
|
119
|
+
context: buildRedirectURL({
|
|
120
|
+
context: rawSamlRequest,
|
|
121
|
+
type: urlParams.samlRequest,
|
|
122
|
+
isSigned: metadata.sp.isAuthnRequestSigned(),
|
|
123
|
+
entitySetting: spSetting,
|
|
124
|
+
baseUrl: base,
|
|
125
|
+
relayState: spSetting.relayState,
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
throw new Error('ERR_GENERATE_REDIRECT_LOGIN_REQUEST_MISSING_METADATA');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @desc Redirect URL for login response
|
|
133
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
134
|
+
* @param {object} entity object includes both idp and sp
|
|
135
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
136
|
+
* @param {String} relayState the relaystate sent by sp corresponding request
|
|
137
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
138
|
+
*/
|
|
139
|
+
function loginResponseRedirectURL(requestInfo, entity, user = {}, relayState, customTagReplacement) {
|
|
140
|
+
const idpSetting = entity.idp.entitySetting;
|
|
141
|
+
const spSetting = entity.sp.entitySetting;
|
|
142
|
+
const metadata = {
|
|
143
|
+
idp: entity.idp.entityMeta,
|
|
144
|
+
sp: entity.sp.entityMeta,
|
|
145
|
+
};
|
|
146
|
+
let id = idpSetting.generateID();
|
|
147
|
+
if (metadata && metadata.idp && metadata.sp) {
|
|
148
|
+
const base = metadata.sp.getAssertionConsumerService(binding.redirect) ?? 'https://signin.volcengine.com/saml/sso';
|
|
149
|
+
if (!base) {
|
|
150
|
+
throw new Error('dont have a base url');
|
|
151
|
+
}
|
|
152
|
+
let rawSamlResponse;
|
|
153
|
+
//
|
|
154
|
+
const nameIDFormat = idpSetting.nameIDFormat;
|
|
155
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
156
|
+
const nowTime = new Date();
|
|
157
|
+
// Five minutes later : nowtime + 5 * 60 * 1000 (in milliseconds)
|
|
158
|
+
const fiveMinutesLaterTime = new Date(nowTime.getTime() + 300_000);
|
|
159
|
+
const tvalue = {
|
|
160
|
+
ID: id,
|
|
161
|
+
AssertionID: idpSetting.generateID(),
|
|
162
|
+
Destination: base,
|
|
163
|
+
SubjectRecipient: base,
|
|
164
|
+
Issuer: metadata.idp.getEntityID(),
|
|
165
|
+
Audience: metadata.sp.getEntityID(),
|
|
166
|
+
EntityID: metadata.sp.getEntityID(),
|
|
167
|
+
IssueInstant: nowTime.toISOString(),
|
|
168
|
+
AssertionConsumerServiceURL: base,
|
|
169
|
+
StatusCode: urn_js_1.namespace.statusCode.success,
|
|
170
|
+
// can be customized
|
|
171
|
+
ConditionsNotBefore: nowTime.toISOString(),
|
|
172
|
+
ConditionsNotOnOrAfter: fiveMinutesLaterTime.toISOString(),
|
|
173
|
+
SubjectConfirmationDataNotOnOrAfter: fiveMinutesLaterTime.toISOString(),
|
|
174
|
+
NameIDFormat: selectedNameIDFormat,
|
|
175
|
+
NameID: user.email || '',
|
|
176
|
+
InResponseTo: (0, utility_js_1.get)(requestInfo, 'extract.request.id', ''),
|
|
177
|
+
AuthnStatement: '',
|
|
178
|
+
AttributeStatement: '',
|
|
179
|
+
};
|
|
180
|
+
if (idpSetting.loginResponseTemplate && customTagReplacement) {
|
|
181
|
+
const template = customTagReplacement(idpSetting.loginResponseTemplate.context);
|
|
182
|
+
id = (0, utility_js_1.get)(template, 'id', null);
|
|
183
|
+
rawSamlResponse = (0, utility_js_1.get)(template, 'context', null);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (requestInfo !== null) {
|
|
187
|
+
tvalue.InResponseTo = requestInfo.extract.request.id;
|
|
188
|
+
}
|
|
189
|
+
rawSamlResponse = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLoginResponseTemplate.context, tvalue);
|
|
190
|
+
}
|
|
191
|
+
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm } = idpSetting;
|
|
192
|
+
const config = {
|
|
193
|
+
privateKey,
|
|
194
|
+
privateKeyPass,
|
|
195
|
+
signatureAlgorithm,
|
|
196
|
+
signingCert: metadata.idp.getX509Certificate('signing'),
|
|
197
|
+
isBase64Output: false,
|
|
198
|
+
};
|
|
199
|
+
// step: sign assertion ? -> encrypted ? -> sign message ?
|
|
200
|
+
if (metadata.sp.isWantAssertionsSigned()) {
|
|
201
|
+
rawSamlResponse = libsaml_js_1.default.constructSAMLSignature({
|
|
202
|
+
...config,
|
|
203
|
+
rawSamlMessage: rawSamlResponse,
|
|
204
|
+
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
205
|
+
referenceTagXPath: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']",
|
|
206
|
+
signatureConfig: {
|
|
207
|
+
prefix: 'ds',
|
|
208
|
+
location: {
|
|
209
|
+
reference: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']/*[local-name(.)='Issuer']",
|
|
210
|
+
action: 'after'
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// Like in post binding, SAML response is always signed
|
|
216
|
+
return {
|
|
217
|
+
id,
|
|
218
|
+
context: buildRedirectURL({
|
|
219
|
+
baseUrl: base,
|
|
220
|
+
type: urlParams.samlResponse,
|
|
221
|
+
isSigned: true,
|
|
222
|
+
context: rawSamlResponse,
|
|
223
|
+
entitySetting: idpSetting,
|
|
224
|
+
relayState,
|
|
225
|
+
}),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
throw new Error('ERR_GENERATE_REDIRECT_LOGIN_RESPONSE_MISSING_METADATA');
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* @desc Redirect URL for logout request
|
|
232
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
233
|
+
* @param {object} entity object includes both idp and sp
|
|
234
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
235
|
+
* @return {string} redirect URL
|
|
236
|
+
*/
|
|
237
|
+
function logoutRequestRedirectURL(user, entity, relayState, customTagReplacement) {
|
|
238
|
+
const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta };
|
|
239
|
+
const initSetting = entity.init.entitySetting;
|
|
240
|
+
let id = initSetting.generateID();
|
|
241
|
+
const nameIDFormat = initSetting.nameIDFormat;
|
|
242
|
+
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
243
|
+
if (metadata && metadata.init && metadata.target) {
|
|
244
|
+
const base = metadata.target.getSingleLogoutService(binding.redirect);
|
|
245
|
+
let rawSamlRequest = '';
|
|
246
|
+
const requiredTags = {
|
|
247
|
+
ID: id,
|
|
248
|
+
Destination: base,
|
|
249
|
+
EntityID: metadata.init.getEntityID(),
|
|
250
|
+
Issuer: metadata.init.getEntityID(),
|
|
251
|
+
IssueInstant: new Date().toISOString(),
|
|
252
|
+
NameIDFormat: selectedNameIDFormat,
|
|
253
|
+
NameID: user.logoutNameID,
|
|
254
|
+
SessionIndex: user.sessionIndex,
|
|
255
|
+
};
|
|
256
|
+
if (initSetting.logoutRequestTemplate && customTagReplacement) {
|
|
257
|
+
const info = customTagReplacement(initSetting.logoutRequestTemplate, requiredTags);
|
|
258
|
+
id = (0, utility_js_1.get)(info, 'id', null);
|
|
259
|
+
rawSamlRequest = (0, utility_js_1.get)(info, 'context', null);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
rawSamlRequest = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLogoutRequestTemplate.context, requiredTags);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
id,
|
|
266
|
+
context: buildRedirectURL({
|
|
267
|
+
context: rawSamlRequest,
|
|
268
|
+
relayState,
|
|
269
|
+
type: urlParams.logoutRequest,
|
|
270
|
+
isSigned: entity.target.entitySetting.wantLogoutRequestSigned,
|
|
271
|
+
entitySetting: initSetting,
|
|
272
|
+
baseUrl: base,
|
|
273
|
+
}),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
throw new Error('ERR_GENERATE_REDIRECT_LOGOUT_REQUEST_MISSING_METADATA');
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* @desc Redirect URL for logout response
|
|
280
|
+
* @param {object} requescorresponding request, used to obtain the id
|
|
281
|
+
* @param {object} entity object includes both idp and sp
|
|
282
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
283
|
+
*/
|
|
284
|
+
function logoutResponseRedirectURL(requestInfo, entity, relayState, customTagReplacement) {
|
|
285
|
+
const metadata = {
|
|
286
|
+
init: entity.init.entityMeta,
|
|
287
|
+
target: entity.target.entityMeta,
|
|
288
|
+
};
|
|
289
|
+
const initSetting = entity.init.entitySetting;
|
|
290
|
+
let id = initSetting.generateID();
|
|
291
|
+
if (metadata && metadata.init && metadata.target) {
|
|
292
|
+
const base = metadata.target.getSingleLogoutService(binding.redirect);
|
|
293
|
+
let rawSamlResponse;
|
|
294
|
+
if (initSetting.logoutResponseTemplate && customTagReplacement) {
|
|
295
|
+
const template = customTagReplacement(initSetting.logoutResponseTemplate);
|
|
296
|
+
id = (0, utility_js_1.get)(template, 'id', null);
|
|
297
|
+
rawSamlResponse = (0, utility_js_1.get)(template, 'context', null);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const tvalue = {
|
|
301
|
+
ID: id,
|
|
302
|
+
Destination: base,
|
|
303
|
+
Issuer: metadata.init.getEntityID(),
|
|
304
|
+
EntityID: metadata.init.getEntityID(),
|
|
305
|
+
IssueInstant: new Date().toISOString(),
|
|
306
|
+
StatusCode: urn_js_1.namespace.statusCode.success,
|
|
307
|
+
};
|
|
308
|
+
if (requestInfo && requestInfo.extract && requestInfo.extract.request) {
|
|
309
|
+
tvalue.InResponseTo = requestInfo.extract.request.id;
|
|
310
|
+
}
|
|
311
|
+
rawSamlResponse = libsaml_js_1.default.replaceTagsByValue(libsaml_js_1.default.defaultLogoutResponseTemplate.context, tvalue);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
id,
|
|
315
|
+
context: buildRedirectURL({
|
|
316
|
+
baseUrl: base,
|
|
317
|
+
type: urlParams.logoutResponse,
|
|
318
|
+
isSigned: entity.target.entitySetting.wantLogoutResponseSigned,
|
|
319
|
+
context: rawSamlResponse,
|
|
320
|
+
entitySetting: initSetting,
|
|
321
|
+
relayState,
|
|
322
|
+
}),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
throw new Error('ERR_GENERATE_REDIRECT_LOGOUT_RESPONSE_MISSING_METADATA');
|
|
326
|
+
}
|
|
327
|
+
const redirectBinding = {
|
|
328
|
+
loginRequestRedirectURL,
|
|
329
|
+
loginResponseRedirectURL,
|
|
330
|
+
logoutRequestRedirectURL,
|
|
331
|
+
logoutResponseRedirectURL,
|
|
332
|
+
};
|
|
333
|
+
exports.default = redirectBinding;
|
|
333
334
|
//# sourceMappingURL=binding-redirect.js.map
|