forked from node-saml/node-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.ts
More file actions
41 lines (35 loc) · 1.24 KB
/
Copy pathutility.ts
File metadata and controls
41 lines (35 loc) · 1.24 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
import { SamlSigningOptions } from "./types";
import { signXml } from "./xml";
export function assertRequired<T>(value: T | null | undefined, error?: string): asserts value {
if (value === undefined || value === null || (typeof value === "string" && value.length === 0)) {
throw new TypeError(error ?? "value does not exist");
}
}
export function assertBooleanIfPresent<T>(
value: T | null | undefined,
error?: string,
): asserts value {
if (value != null && typeof value != "boolean") {
throw new TypeError(error ?? "value is set but not boolean");
}
}
export function signXmlResponse(samlMessage: string, options: SamlSigningOptions): string {
const responseXpath =
'//*[local-name(.)="Response" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]';
return signXml(
samlMessage,
responseXpath,
{ reference: responseXpath, action: "append" },
options,
);
}
export function signXmlMetadata(metadataXml: string, options: SamlSigningOptions): string {
const metadataXpath =
'//*[local-name(.)="EntityDescriptor" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:metadata"]';
return signXml(
metadataXml,
metadataXpath,
{ reference: metadataXpath, action: "prepend" },
options,
);
}