samlesa 2.13.0 → 2.14.1
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/LICENSE +1 -1
- package/README.md +36 -65
- package/build/.idea/deployment.xml +14 -0
- package/{src → build}/.idea/modules.xml +1 -1
- package/build/.idea/workspace.xml +57 -0
- package/build/index.js +18 -54
- package/build/index.js.map +1 -1
- package/build/src/api.js +18 -24
- package/build/src/api.js.map +1 -1
- package/build/src/binding-post.js +337 -365
- package/build/src/binding-post.js.map +1 -1
- package/build/src/binding-redirect.js +312 -340
- package/build/src/binding-redirect.js.map +1 -1
- package/build/src/binding-simplesign.js +201 -229
- package/build/src/binding-simplesign.js.map +1 -1
- package/build/src/entity-idp.js +119 -127
- package/build/src/entity-idp.js.map +1 -1
- package/build/src/entity-sp.js +88 -96
- package/build/src/entity-sp.js.map +1 -1
- package/build/src/entity.js +193 -225
- package/build/src/entity.js.map +1 -1
- package/build/src/extractor.js +361 -369
- package/build/src/extractor.js.map +1 -1
- package/build/src/flow.js +313 -320
- package/build/src/flow.js.map +1 -1
- package/build/src/libsaml.js +693 -721
- package/build/src/libsaml.js.map +1 -1
- package/build/src/metadata-idp.js +119 -127
- package/build/src/metadata-idp.js.map +1 -1
- package/build/src/metadata-sp.js +223 -231
- package/build/src/metadata-sp.js.map +1 -1
- package/build/src/metadata.js +138 -166
- package/build/src/metadata.js.map +1 -1
- package/build/src/types.js +4 -11
- package/build/src/types.js.map +1 -1
- package/build/src/urn.js +204 -212
- package/build/src/urn.js.map +1 -1
- package/build/src/utility.js +277 -292
- package/build/src/utility.js.map +1 -1
- package/build/src/validator.js +24 -27
- package/build/src/validator.js.map +1 -1
- package/package.json +19 -14
- package/types/api.d.ts +15 -0
- package/types/api.d.ts.map +1 -0
- package/types/binding-post.d.ts +48 -0
- package/types/binding-post.d.ts.map +1 -0
- package/types/binding-redirect.d.ts +54 -0
- package/types/binding-redirect.d.ts.map +1 -0
- package/types/binding-simplesign.d.ts +41 -0
- package/types/binding-simplesign.d.ts.map +1 -0
- package/types/entity-idp.d.ts +38 -0
- package/types/entity-idp.d.ts.map +1 -0
- package/types/entity-sp.d.ts +38 -0
- package/types/entity-sp.d.ts.map +1 -0
- package/types/entity.d.ts +100 -0
- package/types/entity.d.ts.map +1 -0
- package/types/extractor.d.ts +26 -0
- package/types/extractor.d.ts.map +1 -0
- package/types/flow.d.ts +7 -0
- package/types/flow.d.ts.map +1 -0
- package/types/index.d.ts +11 -10
- package/types/index.d.ts.map +1 -0
- package/types/libsaml.d.ts +208 -0
- package/types/libsaml.d.ts.map +1 -0
- package/types/metadata-idp.d.ts +25 -0
- package/types/metadata-idp.d.ts.map +1 -0
- package/types/metadata-sp.d.ts +37 -0
- package/types/metadata-sp.d.ts.map +1 -0
- package/types/metadata.d.ts +58 -0
- package/types/metadata.d.ts.map +1 -0
- package/types/src/api.d.ts +15 -13
- package/types/src/api.d.ts.map +1 -0
- package/types/src/binding-post.d.ts +48 -47
- package/types/src/binding-post.d.ts.map +1 -0
- package/types/src/binding-redirect.d.ts +54 -53
- package/types/src/binding-redirect.d.ts.map +1 -0
- package/types/src/binding-simplesign.d.ts +41 -40
- package/types/src/binding-simplesign.d.ts.map +1 -0
- package/types/src/entity-idp.d.ts +38 -37
- package/types/src/entity-idp.d.ts.map +1 -0
- package/types/src/entity-sp.d.ts +38 -36
- package/types/src/entity-sp.d.ts.map +1 -0
- package/types/src/entity.d.ts +100 -101
- package/types/src/entity.d.ts.map +1 -0
- package/types/src/extractor.d.ts +26 -25
- package/types/src/extractor.d.ts.map +1 -0
- package/types/src/flow.d.ts +7 -6
- package/types/src/flow.d.ts.map +1 -0
- package/types/src/libsaml.d.ts +208 -209
- package/types/src/libsaml.d.ts.map +1 -0
- package/types/src/metadata-idp.d.ts +25 -24
- package/types/src/metadata-idp.d.ts.map +1 -0
- package/types/src/metadata-sp.d.ts +37 -36
- package/types/src/metadata-sp.d.ts.map +1 -0
- package/types/src/metadata.d.ts +58 -59
- package/types/src/metadata.d.ts.map +1 -0
- package/types/src/types.d.ts +128 -129
- package/types/src/types.d.ts.map +1 -0
- package/types/src/urn.d.ts +195 -194
- package/types/src/urn.d.ts.map +1 -0
- package/types/src/utility.d.ts +133 -134
- package/types/src/utility.d.ts.map +1 -0
- package/types/src/validator.d.ts +4 -3
- package/types/src/validator.d.ts.map +1 -0
- package/types/types.d.ts +128 -0
- package/types/types.d.ts.map +1 -0
- package/types/urn.d.ts +195 -0
- package/types/urn.d.ts.map +1 -0
- package/types/utility.d.ts +133 -0
- package/types/utility.d.ts.map +1 -0
- package/types/validator.d.ts +4 -0
- package/types/validator.d.ts.map +1 -0
- package/.editorconfig +0 -19
- package/.github/FUNDING.yml +0 -1
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.pre-commit.sh +0 -15
- package/.snyk +0 -8
- package/.travis.yml +0 -29
- package/Makefile +0 -25
- package/index.d.ts +0 -10
- package/index.js +0 -19
- package/index.js.map +0 -1
- package/index.ts +0 -28
- package/qodana.yaml +0 -29
- package/src/.idea/src.iml +0 -12
- package/src/.idea/vcs.xml +0 -6
- package/src/api.ts +0 -36
- package/src/binding-post.ts +0 -348
- package/src/binding-redirect.ts +0 -356
- package/src/binding-simplesign.ts +0 -238
- package/src/entity-idp.ts +0 -153
- package/src/entity-sp.ts +0 -114
- package/src/entity.ts +0 -243
- package/src/extractor.ts +0 -392
- package/src/flow.ts +0 -467
- package/src/libsaml.ts +0 -895
- package/src/metadata-idp.ts +0 -146
- package/src/metadata-sp.ts +0 -268
- package/src/metadata.ts +0 -166
- package/src/types.ts +0 -153
- package/src/urn.ts +0 -211
- package/src/utility.ts +0 -319
- package/src/validator.ts +0 -39
- package/tsconfig.json +0 -38
- package/tslint.json +0 -35
- package/types.d.ts +0 -2
- /package/{.idea/samlify.iml → build/.idea/build.iml} +0 -0
package/src/binding-post.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file binding-post.ts
|
|
3
|
-
* @author tngan
|
|
4
|
-
* @desc Binding-level API, declare the functions using POST binding
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { wording, namespace, StatusCode } from './urn.js';
|
|
8
|
-
import { BindingContext } from './entity.js';
|
|
9
|
-
import libsaml from './libsaml.js';
|
|
10
|
-
import utility, { get } from './utility.js';
|
|
11
|
-
|
|
12
|
-
const binding = wording.binding;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @desc Generate a base64 encoded login request
|
|
16
|
-
* @param {string} referenceTagXPath reference uri
|
|
17
|
-
* @param {object} entity object includes both idp and sp
|
|
18
|
-
* @param {function} customTagReplacement used when developers have their own login response template
|
|
19
|
-
*/
|
|
20
|
-
function base64LoginRequest(referenceTagXPath: string, entity: any, customTagReplacement?: (template: string) => BindingContext): BindingContext {
|
|
21
|
-
const metadata = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta };
|
|
22
|
-
const spSetting = entity.sp.entitySetting;
|
|
23
|
-
let id: string = '';
|
|
24
|
-
|
|
25
|
-
if (metadata && metadata.idp && metadata.sp) {
|
|
26
|
-
const base = metadata.idp.getSingleSignOnService(binding.post);
|
|
27
|
-
let rawSamlRequest: string;
|
|
28
|
-
if (spSetting.loginRequestTemplate && customTagReplacement) {
|
|
29
|
-
const info = customTagReplacement(spSetting.loginRequestTemplate.context);
|
|
30
|
-
id = get(info, 'id', null);
|
|
31
|
-
rawSamlRequest = get(info, 'context', null);
|
|
32
|
-
} else {
|
|
33
|
-
const nameIDFormat = spSetting.nameIDFormat;
|
|
34
|
-
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
35
|
-
id = spSetting.generateID();
|
|
36
|
-
rawSamlRequest = libsaml.replaceTagsByValue(libsaml.defaultLoginRequestTemplate.context, {
|
|
37
|
-
ID: id,
|
|
38
|
-
Destination: base,
|
|
39
|
-
Issuer: metadata.sp.getEntityID(),
|
|
40
|
-
IssueInstant: new Date().toISOString(),
|
|
41
|
-
AssertionConsumerServiceURL: metadata.sp.getAssertionConsumerService(binding.post),
|
|
42
|
-
EntityID: metadata.sp.getEntityID(),
|
|
43
|
-
AllowCreate: spSetting.allowCreate,
|
|
44
|
-
NameIDFormat: selectedNameIDFormat
|
|
45
|
-
} as any);
|
|
46
|
-
}
|
|
47
|
-
if (metadata.idp.isWantAuthnRequestsSigned()) {
|
|
48
|
-
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = spSetting;
|
|
49
|
-
return {
|
|
50
|
-
id,
|
|
51
|
-
context: libsaml.constructSAMLSignature({
|
|
52
|
-
referenceTagXPath,
|
|
53
|
-
privateKey,
|
|
54
|
-
privateKeyPass,
|
|
55
|
-
signatureAlgorithm,
|
|
56
|
-
transformationAlgorithms,
|
|
57
|
-
rawSamlMessage: rawSamlRequest,
|
|
58
|
-
signingCert: metadata.sp.getX509Certificate('signing'),
|
|
59
|
-
signatureConfig: spSetting.signatureConfig || {
|
|
60
|
-
prefix: 'ds',
|
|
61
|
-
location: { reference: "/*[local-name(.)='AuthnRequest']/*[local-name(.)='Issuer']", action: 'after' },
|
|
62
|
-
}
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
// No need to embeded XML signature
|
|
67
|
-
return {
|
|
68
|
-
id,
|
|
69
|
-
context: utility.base64Encode(rawSamlRequest),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
throw new Error('ERR_GENERATE_POST_LOGIN_REQUEST_MISSING_METADATA');
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @desc Generate a base64 encoded login response
|
|
76
|
-
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
77
|
-
* @param {object} entity object includes both idp and sp
|
|
78
|
-
* @param {object} user current logged user (e.g. req.user)
|
|
79
|
-
* @param {function} customTagReplacement used when developers have their own login response template
|
|
80
|
-
* @param {boolean} encryptThenSign whether or not to encrypt then sign first (if signing). Defaults to sign-then-encrypt
|
|
81
|
-
* @param AttributeStatement
|
|
82
|
-
*/
|
|
83
|
-
async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any = {}, customTagReplacement?: (template: string) => BindingContext, encryptThenSign: boolean = false , AttributeStatement=[]): Promise<BindingContext> {
|
|
84
|
-
const idpSetting = entity.idp.entitySetting;
|
|
85
|
-
const spSetting = entity.sp.entitySetting;
|
|
86
|
-
const id = idpSetting.generateID();
|
|
87
|
-
const metadata = {
|
|
88
|
-
idp: entity.idp.entityMeta,
|
|
89
|
-
sp: entity.sp.entityMeta,
|
|
90
|
-
};
|
|
91
|
-
const nameIDFormat = idpSetting.nameIDFormat;
|
|
92
|
-
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (metadata && metadata.idp && metadata.sp) {
|
|
96
|
-
const base = metadata.sp.getAssertionConsumerService(binding.post);
|
|
97
|
-
let rawSamlResponse;
|
|
98
|
-
const nowTime = new Date();
|
|
99
|
-
const spEntityID = metadata.sp.getEntityID();
|
|
100
|
-
const oneMinutesLaterTime = new Date(nowTime.getTime());
|
|
101
|
-
oneMinutesLaterTime.setMinutes(oneMinutesLaterTime.getMinutes() + 5);
|
|
102
|
-
const OneMinutesLater = oneMinutesLaterTime.toISOString();
|
|
103
|
-
const now = nowTime.toISOString();
|
|
104
|
-
console.log(`现在是北京时间:${nowTime.toLocaleString()}`)
|
|
105
|
-
console.log(`现在是两分钟时间:${oneMinutesLaterTime.toLocaleString()}`)
|
|
106
|
-
const acl = metadata.sp.getAssertionConsumerService(binding.post);
|
|
107
|
-
const sessionIndex = 'session'+idpSetting.generateID(); // 这个是当前系统的会话索引,用于单点注销
|
|
108
|
-
const tenHoursLaterTime = new Date(nowTime.getTime());
|
|
109
|
-
tenHoursLaterTime.setHours(tenHoursLaterTime.getHours() + 10);
|
|
110
|
-
const tenHoursLater = tenHoursLaterTime.toISOString();
|
|
111
|
-
const tvalue: any = {
|
|
112
|
-
ID: id,
|
|
113
|
-
AssertionID: idpSetting.generateID(),
|
|
114
|
-
Destination: base,
|
|
115
|
-
Audience: spEntityID,
|
|
116
|
-
EntityID: spEntityID,
|
|
117
|
-
SubjectRecipient: acl,
|
|
118
|
-
Issuer: metadata.idp.getEntityID(),
|
|
119
|
-
IssueInstant: now,
|
|
120
|
-
AssertionConsumerServiceURL: acl,
|
|
121
|
-
StatusCode: StatusCode.Success,
|
|
122
|
-
// can be customized
|
|
123
|
-
ConditionsNotBefore: now,
|
|
124
|
-
ConditionsNotOnOrAfter: OneMinutesLater,
|
|
125
|
-
SubjectConfirmationDataNotOnOrAfter: OneMinutesLater,
|
|
126
|
-
NameIDFormat: selectedNameIDFormat,
|
|
127
|
-
NameID: user?.NameID || '',
|
|
128
|
-
InResponseTo: get(requestInfo, 'extract.request.id', ''),
|
|
129
|
-
AuthnStatement: `<saml:AuthnStatement AuthnInstant="${now}" SessionNotOnOrAfter="${tenHoursLater}" SessionIndex="${sessionIndex}"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement>`,
|
|
130
|
-
AttributeStatement: libsaml.attributeStatementBuilder(AttributeStatement),
|
|
131
|
-
};
|
|
132
|
-
if (idpSetting.loginResponseTemplate && customTagReplacement) {
|
|
133
|
-
const template = customTagReplacement(idpSetting.loginResponseTemplate.context);
|
|
134
|
-
rawSamlResponse = get(template, 'context', null);
|
|
135
|
-
} else {
|
|
136
|
-
if (requestInfo !== null) {
|
|
137
|
-
tvalue.InResponseTo = requestInfo?.extract?.request?.id ?? '';
|
|
138
|
-
}
|
|
139
|
-
rawSamlResponse = libsaml.replaceTagsByValue(libsaml.defaultLoginResponseTemplate.context, tvalue);
|
|
140
|
-
}
|
|
141
|
-
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm } = idpSetting;
|
|
142
|
-
const config = {
|
|
143
|
-
privateKey,
|
|
144
|
-
privateKeyPass,
|
|
145
|
-
signatureAlgorithm,
|
|
146
|
-
signingCert: metadata.idp.getX509Certificate('signing'),
|
|
147
|
-
isBase64Output: false,
|
|
148
|
-
};
|
|
149
|
-
// step: sign assertion ? -> encrypted ? -> sign message ?
|
|
150
|
-
if (metadata.sp.isWantAssertionsSigned()) {
|
|
151
|
-
// console.debug('sp wants assertion signed');
|
|
152
|
-
rawSamlResponse = libsaml.constructSAMLSignature({
|
|
153
|
-
...config,
|
|
154
|
-
rawSamlMessage: rawSamlResponse,
|
|
155
|
-
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
156
|
-
referenceTagXPath: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']",
|
|
157
|
-
signatureConfig: {
|
|
158
|
-
prefix: 'ds',
|
|
159
|
-
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Assertion']/*[local-name(.)='Issuer']", action: 'after' },
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// console.debug('after assertion signed', rawSamlResponse);
|
|
165
|
-
|
|
166
|
-
// SAML response must be signed sign message first, then encrypt
|
|
167
|
-
if (!encryptThenSign && (spSetting.wantMessageSigned || !metadata.sp.isWantAssertionsSigned())) {
|
|
168
|
-
// console.debug('sign then encrypt and sign entire message');
|
|
169
|
-
rawSamlResponse = libsaml.constructSAMLSignature({
|
|
170
|
-
...config,
|
|
171
|
-
rawSamlMessage: rawSamlResponse,
|
|
172
|
-
isMessageSigned: true,
|
|
173
|
-
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
174
|
-
signatureConfig: spSetting.signatureConfig || {
|
|
175
|
-
prefix: 'ds',
|
|
176
|
-
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Issuer']", action: 'after' },
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// console.debug('after message signed', rawSamlResponse);
|
|
182
|
-
|
|
183
|
-
if (idpSetting.isAssertionEncrypted) {
|
|
184
|
-
// console.debug('idp is configured to do encryption');
|
|
185
|
-
const context = await libsaml.encryptAssertion(entity.idp, entity.sp, rawSamlResponse);
|
|
186
|
-
if (encryptThenSign) {
|
|
187
|
-
//need to decode it
|
|
188
|
-
rawSamlResponse = utility.base64Decode(context) as string;
|
|
189
|
-
} else {
|
|
190
|
-
return Promise.resolve({ id, context });
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
//sign after encrypting
|
|
195
|
-
if (encryptThenSign && (spSetting.wantMessageSigned || !metadata.sp.isWantAssertionsSigned())) {
|
|
196
|
-
rawSamlResponse = libsaml.constructSAMLSignature({
|
|
197
|
-
...config,
|
|
198
|
-
rawSamlMessage: rawSamlResponse,
|
|
199
|
-
isMessageSigned: true,
|
|
200
|
-
transformationAlgorithms: spSetting.transformationAlgorithms,
|
|
201
|
-
signatureConfig: spSetting.signatureConfig || {
|
|
202
|
-
prefix: 'ds',
|
|
203
|
-
location: { reference: "/*[local-name(.)='Response']/*[local-name(.)='Issuer']", action: 'after' },
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
console.log(rawSamlResponse);
|
|
208
|
-
console.log('看一下---------------------------')
|
|
209
|
-
return Promise.resolve({
|
|
210
|
-
id,
|
|
211
|
-
context: utility.base64Encode(rawSamlResponse),
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
throw new Error('ERR_GENERATE_POST_LOGIN_RESPONSE_MISSING_METADATA');
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* @desc Generate a base64 encoded logout request
|
|
221
|
-
* @param {object} user current logged user (e.g. req.user)
|
|
222
|
-
* @param {string} referenceTagXPath reference uri
|
|
223
|
-
* @param {object} entity object includes both idp and sp
|
|
224
|
-
* @param {function} customTagReplacement used when developers have their own login response template
|
|
225
|
-
* @return {string} base64 encoded request
|
|
226
|
-
*/
|
|
227
|
-
function base64LogoutRequest(user, referenceTagXPath, entity, customTagReplacement?: (template: string) => BindingContext): BindingContext {
|
|
228
|
-
const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta };
|
|
229
|
-
const initSetting = entity.init.entitySetting;
|
|
230
|
-
const nameIDFormat = initSetting.nameIDFormat;
|
|
231
|
-
const selectedNameIDFormat = Array.isArray(nameIDFormat) ? nameIDFormat[0] : nameIDFormat; let id: string = '';
|
|
232
|
-
if (metadata && metadata.init && metadata.target) {
|
|
233
|
-
let rawSamlRequest: string;
|
|
234
|
-
if (initSetting.logoutRequestTemplate && customTagReplacement) {
|
|
235
|
-
const template = customTagReplacement(initSetting.logoutRequestTemplate.context);
|
|
236
|
-
id = get(template, 'id', null);
|
|
237
|
-
rawSamlRequest = get(template, 'context', null);
|
|
238
|
-
} else {
|
|
239
|
-
id = initSetting.generateID();
|
|
240
|
-
const tvalue: any = {
|
|
241
|
-
ID: id,
|
|
242
|
-
Destination: metadata.target.getSingleLogoutService(binding.post),
|
|
243
|
-
Issuer: metadata.init.getEntityID(),
|
|
244
|
-
IssueInstant: new Date().toISOString(),
|
|
245
|
-
EntityID: metadata.init.getEntityID(),
|
|
246
|
-
NameIDFormat: selectedNameIDFormat,
|
|
247
|
-
NameID: user.NameID || '',
|
|
248
|
-
};
|
|
249
|
-
rawSamlRequest = libsaml.replaceTagsByValue(libsaml.defaultLogoutRequestTemplate.context, tvalue);
|
|
250
|
-
}
|
|
251
|
-
if (entity.target.entitySetting.wantLogoutRequestSigned) {
|
|
252
|
-
// Need to embeded XML signature
|
|
253
|
-
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = initSetting;
|
|
254
|
-
return {
|
|
255
|
-
id,
|
|
256
|
-
context: libsaml.constructSAMLSignature({
|
|
257
|
-
referenceTagXPath,
|
|
258
|
-
privateKey,
|
|
259
|
-
privateKeyPass,
|
|
260
|
-
signatureAlgorithm,
|
|
261
|
-
transformationAlgorithms,
|
|
262
|
-
rawSamlMessage: rawSamlRequest,
|
|
263
|
-
signingCert: metadata.init.getX509Certificate('signing'),
|
|
264
|
-
signatureConfig: initSetting.signatureConfig || {
|
|
265
|
-
prefix: 'ds',
|
|
266
|
-
location: { reference: "/*[local-name(.)='LogoutRequest']/*[local-name(.)='Issuer']", action: 'after' },
|
|
267
|
-
}
|
|
268
|
-
}),
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
id,
|
|
273
|
-
context: utility.base64Encode(rawSamlRequest),
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
throw new Error('ERR_GENERATE_POST_LOGOUT_REQUEST_MISSING_METADATA');
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* @desc Generate a base64 encoded logout response
|
|
280
|
-
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
281
|
-
* @param {string} referenceTagXPath reference uri
|
|
282
|
-
* @param {object} entity object includes both idp and sp
|
|
283
|
-
* @param {function} customTagReplacement used when developers have their own login response template
|
|
284
|
-
*/
|
|
285
|
-
function base64LogoutResponse(requestInfo: any, entity: any, customTagReplacement: (template: string) => BindingContext): BindingContext {
|
|
286
|
-
const metadata = {
|
|
287
|
-
init: entity.init.entityMeta,
|
|
288
|
-
target: entity.target.entityMeta,
|
|
289
|
-
};
|
|
290
|
-
let id: string = '';
|
|
291
|
-
const initSetting = entity.init.entitySetting;
|
|
292
|
-
if (metadata && metadata.init && metadata.target) {
|
|
293
|
-
let rawSamlResponse;
|
|
294
|
-
if (initSetting.logoutResponseTemplate) {
|
|
295
|
-
const template = customTagReplacement(initSetting.logoutResponseTemplate.context);
|
|
296
|
-
id = template.id;
|
|
297
|
-
rawSamlResponse = template.context;
|
|
298
|
-
} else {
|
|
299
|
-
id = initSetting.generateID();
|
|
300
|
-
const tvalue: any = {
|
|
301
|
-
ID: id,
|
|
302
|
-
Destination: metadata.target.getSingleLogoutService(binding.post),
|
|
303
|
-
EntityID: metadata.init.getEntityID(),
|
|
304
|
-
Issuer: metadata.init.getEntityID(),
|
|
305
|
-
IssueInstant: new Date().toISOString(),
|
|
306
|
-
StatusCode: StatusCode.Success,
|
|
307
|
-
InResponseTo: get(requestInfo, 'extract.request.id', '')
|
|
308
|
-
};
|
|
309
|
-
rawSamlResponse = libsaml.replaceTagsByValue(libsaml.defaultLogoutResponseTemplate.context, tvalue);
|
|
310
|
-
}
|
|
311
|
-
if (entity.target.entitySetting.wantLogoutResponseSigned) {
|
|
312
|
-
const { privateKey, privateKeyPass, requestSignatureAlgorithm: signatureAlgorithm, transformationAlgorithms } = initSetting;
|
|
313
|
-
return {
|
|
314
|
-
id,
|
|
315
|
-
context: libsaml.constructSAMLSignature({
|
|
316
|
-
isMessageSigned: true,
|
|
317
|
-
transformationAlgorithms: transformationAlgorithms,
|
|
318
|
-
privateKey,
|
|
319
|
-
privateKeyPass,
|
|
320
|
-
signatureAlgorithm,
|
|
321
|
-
rawSamlMessage: rawSamlResponse,
|
|
322
|
-
signingCert: metadata.init.getX509Certificate('signing'),
|
|
323
|
-
signatureConfig: {
|
|
324
|
-
prefix: 'ds',
|
|
325
|
-
location: {
|
|
326
|
-
reference: "/*[local-name(.)='LogoutResponse']/*[local-name(.)='Issuer']",
|
|
327
|
-
action: 'after'
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}),
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
id,
|
|
335
|
-
context: utility.base64Encode(rawSamlResponse),
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
throw new Error('ERR_GENERATE_POST_LOGOUT_RESPONSE_MISSING_METADATA');
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const postBinding = {
|
|
342
|
-
base64LoginRequest,
|
|
343
|
-
base64LoginResponse,
|
|
344
|
-
base64LogoutRequest,
|
|
345
|
-
base64LogoutResponse,
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
export default postBinding;
|