/
types.ts
161 lines (138 loc) · 5.05 KB
/
types.ts
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
159
160
161
import type { SignedXml } from 'xml-crypto';
import type { EncryptionAlgorithm, KeyEncryptionAlgorithm } from 'xml-encryption';
import type { LoginResponseTemplate, LogoutResponseTemplate } from './libsaml';
import type { BindingNamespace, MessageSignatureOrder } from './urn';
interface SSOService {
isDefault?: boolean;
Binding: BindingNamespace;
Location: string;
}
export type RequestSignatureAlgorithm =
| 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
| 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'
| 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512';
// https://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf (P.16, 18)
export interface MetaElement {
AssertionConsumerService?: any[];
AttributeConsumingService?: any[];
KeyDescriptor?: any[];
NameIDFormat?: any[];
SingleLogoutService?: any[];
}
interface MetadataOptions {
encryptCert?: string | Buffer;
entityID?: string;
nameIDFormat?: string[];
signingCert?: string | Buffer;
singleLogoutService?: SSOService[];
singleSignOnService?: SSOService[];
}
interface MetadataIdpOptions extends MetadataOptions {
requestSignatureAlgorithm?: RequestSignatureAlgorithm;
wantAuthnRequestsSigned?: boolean;
}
interface MetadataSpOptions extends MetadataOptions {
assertionConsumerService?: SSOService[];
authnRequestsSigned?: boolean;
elementsOrder?: (keyof MetaElement)[];
// TODO: Not sure if this is used. Consider removing.
signatureConfig?: Record<string, any>;
wantAssertionsSigned?: boolean;
wantMessageSigned?: boolean;
}
type MetadataFile = string | Buffer;
export type MetadataIdpConstructorOptions = MetadataIdpOptions | MetadataFile;
export type MetadataSpConstructorOptions = MetadataSpOptions | MetadataFile;
export interface SAMLDocumentTemplate {
context?: string;
}
export type SignatureConfig = Parameters<SignedXml['computeSignature']>[1];
export interface EntitySettings {
metadata?: string | Buffer;
entityID?: string;
assertionConsumerService?: SSOService[];
singleLogoutService?: SSOService[];
authnRequestsSigned?: boolean;
isAssertionEncrypted?: boolean;
/** signature algorithm */
requestSignatureAlgorithm?: RequestSignatureAlgorithm;
dataEncryptionAlgorithm?: EncryptionAlgorithm;
keyEncryptionAlgorithm?: KeyEncryptionAlgorithm;
messageSigningOrder?: MessageSignatureOrder;
signatureConfig?: SignatureConfig;
transformationAlgorithms?: string[];
wantAssertionsSigned?: boolean;
wantLogoutRequestSigned?: boolean;
wantLogoutResponseSigned?: boolean;
wantMessageSigned?: boolean;
signingCert?: string | Buffer;
privateKey?: string | Buffer;
privateKeyPass?: string;
encryptCert?: string | Buffer;
encPrivateKey?: string | Buffer;
encPrivateKeyPass?: string;
/** template of login request */
loginRequestTemplate?: SAMLDocumentTemplate;
/** template of logout request */
logoutRequestTemplate?: SAMLDocumentTemplate;
/** template of logout response */
logoutResponseTemplate?: LogoutResponseTemplate;
nameIDFormat?: string[];
allowCreate?: boolean;
// will be deprecated soon
relayState?: string;
// https://github.com/tngan/samlify/issues/337
clockDrifts?: [number, number];
/** customized function used for generating request ID */
generateID?: () => string;
/** Declare the tag of specific xml document node. `TagPrefixKey` currently supports `encryptedAssertion` only */
tagPrefix?: { encryptedAssertion?: string };
}
export interface ServiceProviderSettings extends EntitySettings {
authnRequestsSigned?: boolean;
wantAssertionsSigned?: boolean;
wantMessageSigned?: boolean;
assertionConsumerService?: SSOService[];
loginRequestTemplate?: SAMLDocumentTemplate;
logoutRequestTemplate?: SAMLDocumentTemplate;
transformationAlgorithms?: string[];
allowCreate?: boolean;
// will be deprecated soon
relayState?: string;
// https://github.com/tngan/samlify/issues/337
clockDrifts?: [number, number];
}
export interface IdentityProviderSettings extends EntitySettings {
/** template of login response */
loginResponseTemplate?: LoginResponseTemplate;
singleSignOnService?: SSOService[];
wantAuthnRequestsSigned?: boolean;
wantLogoutRequestSignedResponseSigned?: boolean;
}
export interface ParsedLoginRequest {
authnContextClassRef?: string;
issuer?: string;
nameIDPolicy?: { format?: string; allowCreate?: string };
request?: { id?: string; issueInstant?: string; destination?: string; assertionConsumerServiceUrl?: string };
signature?: string;
}
export interface ParsedLoginResponse {
attributes?: Record<string, string>;
audience?: string;
conditions?: { notBefore: string; notOnOrAfter: string };
issuer?: string;
nameID?: string;
response?: { id?: string; issueInstant?: string; destination?: string; inResponseTo?: string };
sessionIndex?: { authnInstant?: string; sessionNotOnOrAfter?: string; sessionIndex?: string };
}
export interface ParsedLogoutRequest {
request?: { id?: string; issueInstant?: string; destination?: string };
issuer?: string;
nameID?: string;
signature?: string;
}
export interface ParsedLogoutResponse {
response?: { id?: string; destination?: string; inResponseTo?: string };
issuer?: string;
signature?: string;
}