samlesa 2.12.3
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.
- package/.editorconfig +19 -0
- package/.github/FUNDING.yml +1 -0
- package/.idea/compiler.xml +6 -0
- package/.idea/deployment.xml +14 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/samlify.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.pre-commit.sh +15 -0
- package/.snyk +8 -0
- package/.travis.yml +29 -0
- package/LICENSE +22 -0
- package/Makefile +25 -0
- package/README.md +84 -0
- package/build/.idea/workspace.xml +58 -0
- package/build/index.js +65 -0
- package/build/index.js.map +1 -0
- package/build/src/api.js +24 -0
- package/build/src/api.js.map +1 -0
- package/build/src/binding-post.js +369 -0
- package/build/src/binding-post.js.map +1 -0
- package/build/src/binding-redirect.js +333 -0
- package/build/src/binding-redirect.js.map +1 -0
- package/build/src/binding-simplesign.js +233 -0
- package/build/src/binding-simplesign.js.map +1 -0
- package/build/src/entity-idp.js +131 -0
- package/build/src/entity-idp.js.map +1 -0
- package/build/src/entity-sp.js +97 -0
- package/build/src/entity-sp.js.map +1 -0
- package/build/src/entity.js +236 -0
- package/build/src/entity.js.map +1 -0
- package/build/src/extractor.js +370 -0
- package/build/src/extractor.js.map +1 -0
- package/build/src/flow.js +320 -0
- package/build/src/flow.js.map +1 -0
- package/build/src/libsaml.js +642 -0
- package/build/src/libsaml.js.map +1 -0
- package/build/src/metadata-idp.js +128 -0
- package/build/src/metadata-idp.js.map +1 -0
- package/build/src/metadata-sp.js +232 -0
- package/build/src/metadata-sp.js.map +1 -0
- package/build/src/metadata.js +177 -0
- package/build/src/metadata.js.map +1 -0
- package/build/src/types.js +12 -0
- package/build/src/types.js.map +1 -0
- package/build/src/urn.js +213 -0
- package/build/src/urn.js.map +1 -0
- package/build/src/utility.js +249 -0
- package/build/src/utility.js.map +1 -0
- package/build/src/validator.js +27 -0
- package/build/src/validator.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/index.ts +28 -0
- package/package.json +74 -0
- package/qodana.yaml +29 -0
- package/src/.idea/modules.xml +8 -0
- package/src/.idea/src.iml +12 -0
- package/src/.idea/vcs.xml +6 -0
- package/src/api.ts +36 -0
- package/src/binding-post.ts +338 -0
- package/src/binding-redirect.ts +331 -0
- package/src/binding-simplesign.ts +231 -0
- package/src/entity-idp.ts +145 -0
- package/src/entity-sp.ts +114 -0
- package/src/entity.ts +243 -0
- package/src/extractor.ts +392 -0
- package/src/flow.ts +467 -0
- package/src/libsaml.ts +786 -0
- package/src/metadata-idp.ts +146 -0
- package/src/metadata-sp.ts +268 -0
- package/src/metadata.ts +166 -0
- package/src/types.ts +153 -0
- package/src/urn.ts +211 -0
- package/src/utility.ts +248 -0
- package/src/validator.ts +44 -0
- package/tsconfig.json +38 -0
- package/tslint.json +35 -0
- package/types/index.d.ts +10 -0
- package/types/src/api.d.ts +13 -0
- package/types/src/binding-post.d.ts +46 -0
- package/types/src/binding-redirect.d.ts +52 -0
- package/types/src/binding-simplesign.d.ts +39 -0
- package/types/src/entity-idp.d.ts +42 -0
- package/types/src/entity-sp.d.ts +36 -0
- package/types/src/entity.d.ts +99 -0
- package/types/src/extractor.d.ts +25 -0
- package/types/src/flow.d.ts +6 -0
- package/types/src/libsaml.d.ts +210 -0
- package/types/src/metadata-idp.d.ts +24 -0
- package/types/src/metadata-sp.d.ts +36 -0
- package/types/src/metadata.d.ts +57 -0
- package/types/src/types.d.ts +127 -0
- package/types/src/urn.d.ts +194 -0
- package/types/src/utility.d.ts +134 -0
- package/types/src/validator.d.ts +3 -0
- package/types.d.ts +2 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file entity-idp.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc Declares the actions taken by identity provider
|
|
5
|
+
*/
|
|
6
|
+
import Entity, { ESamlHttpRequest } from './entity.js';
|
|
7
|
+
import {
|
|
8
|
+
ServiceProviderConstructor as ServiceProvider,
|
|
9
|
+
ServiceProviderMetadata,
|
|
10
|
+
IdentityProviderMetadata,
|
|
11
|
+
IdentityProviderSettings,
|
|
12
|
+
} from './types.js';
|
|
13
|
+
import libsaml from './libsaml.js';
|
|
14
|
+
import { namespace } from './urn.js';
|
|
15
|
+
import postBinding from './binding-post.js';
|
|
16
|
+
import redirectBinding from './binding-redirect.js';
|
|
17
|
+
import simpleSignBinding from './binding-simplesign.js';
|
|
18
|
+
import { flow, FlowResult } from './flow.js';
|
|
19
|
+
import { isString } from './utility.js';
|
|
20
|
+
import { BindingContext } from './entity.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Identity provider can be configured using either metadata importing or idpSetting
|
|
24
|
+
*/
|
|
25
|
+
export default function(props: IdentityProviderSettings) {
|
|
26
|
+
return new IdentityProvider(props);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Identity provider can be configured using either metadata importing or idpSetting
|
|
31
|
+
*/
|
|
32
|
+
export class IdentityProvider extends Entity {
|
|
33
|
+
|
|
34
|
+
declare entityMeta: IdentityProviderMetadata;
|
|
35
|
+
|
|
36
|
+
constructor(idpSetting: IdentityProviderSettings) {
|
|
37
|
+
const defaultIdpEntitySetting = {
|
|
38
|
+
wantAuthnRequestsSigned: false,
|
|
39
|
+
tagPrefix: {
|
|
40
|
+
encryptedAssertion: 'saml',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const entitySetting = Object.assign(defaultIdpEntitySetting, idpSetting);
|
|
44
|
+
// build attribute part
|
|
45
|
+
if (idpSetting.loginResponseTemplate) {
|
|
46
|
+
if (isString(idpSetting.loginResponseTemplate.context) && Array.isArray(idpSetting.loginResponseTemplate.attributes)) {
|
|
47
|
+
let attributeStatementTemplate;
|
|
48
|
+
let attributeTemplate;
|
|
49
|
+
if (!idpSetting.loginResponseTemplate.additionalTemplates || !idpSetting.loginResponseTemplate.additionalTemplates!.attributeStatementTemplate) {
|
|
50
|
+
attributeStatementTemplate = libsaml.defaultAttributeStatementTemplate;
|
|
51
|
+
} else {
|
|
52
|
+
attributeStatementTemplate = idpSetting.loginResponseTemplate.additionalTemplates!.attributeStatementTemplate!;
|
|
53
|
+
}
|
|
54
|
+
if (!idpSetting.loginResponseTemplate.additionalTemplates || !idpSetting.loginResponseTemplate.additionalTemplates!.attributeTemplate) {
|
|
55
|
+
attributeTemplate = libsaml.defaultAttributeTemplate;
|
|
56
|
+
} else {
|
|
57
|
+
attributeTemplate = idpSetting.loginResponseTemplate.additionalTemplates!.attributeTemplate!;
|
|
58
|
+
}
|
|
59
|
+
const replacement = {
|
|
60
|
+
AttributeStatement: libsaml.attributeStatementBuilder(idpSetting.loginResponseTemplate.attributes, attributeTemplate, attributeStatementTemplate),
|
|
61
|
+
};
|
|
62
|
+
entitySetting.loginResponseTemplate = {
|
|
63
|
+
...entitySetting.loginResponseTemplate,
|
|
64
|
+
context: libsaml.replaceTagsByValue(entitySetting.loginResponseTemplate!.context, replacement),
|
|
65
|
+
};
|
|
66
|
+
} else {
|
|
67
|
+
console.warn('Invalid login response template');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
super(entitySetting, 'idp');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @desc Generates the login response for developers to design their own method
|
|
75
|
+
* @param sp object of service provider
|
|
76
|
+
* @param requestInfo corresponding request, used to obtain the id
|
|
77
|
+
* @param binding protocol binding
|
|
78
|
+
* @param user current logged user (e.g. req.user)
|
|
79
|
+
* @param customTagReplacement used when developers have their own login response template
|
|
80
|
+
* @param encryptThenSign whether or not to encrypt then sign first (if signing)
|
|
81
|
+
* @param relayState the relayState from corresponding request
|
|
82
|
+
*/
|
|
83
|
+
public async createLoginResponse(
|
|
84
|
+
sp: ServiceProvider,
|
|
85
|
+
requestInfo: { [key: string]: any },
|
|
86
|
+
binding: string,
|
|
87
|
+
user: { [key: string]: any },
|
|
88
|
+
customTagReplacement?: (template: string) => BindingContext,
|
|
89
|
+
encryptThenSign?: boolean,
|
|
90
|
+
relayState?: string,
|
|
91
|
+
) {
|
|
92
|
+
const protocol = namespace.binding[binding];
|
|
93
|
+
// can support post, redirect and post simple sign bindings for login response
|
|
94
|
+
let context: any = null;
|
|
95
|
+
switch (protocol) {
|
|
96
|
+
case namespace.binding.post:
|
|
97
|
+
context = await postBinding.base64LoginResponse(requestInfo, {
|
|
98
|
+
idp: this,
|
|
99
|
+
sp,
|
|
100
|
+
}, user, customTagReplacement, encryptThenSign);
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case namespace.binding.simpleSign:
|
|
104
|
+
context = await simpleSignBinding.base64LoginResponse( requestInfo, {
|
|
105
|
+
idp: this, sp,
|
|
106
|
+
}, user, relayState, customTagReplacement);
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case namespace.binding.redirect:
|
|
110
|
+
return redirectBinding.loginResponseRedirectURL(requestInfo, {
|
|
111
|
+
idp: this,
|
|
112
|
+
sp,
|
|
113
|
+
}, user, relayState, customTagReplacement);
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
throw new Error('ERR_CREATE_RESPONSE_UNDEFINED_BINDING');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
...context,
|
|
121
|
+
relayState,
|
|
122
|
+
entityEndpoint: (sp.entityMeta as ServiceProviderMetadata).getAssertionConsumerService(binding) as string,
|
|
123
|
+
type: 'SAMLResponse'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Validation of the parsed URL parameters
|
|
129
|
+
* @param sp ServiceProvider instance
|
|
130
|
+
* @param binding Protocol binding
|
|
131
|
+
* @param req RequesmessageSigningOrderst
|
|
132
|
+
*/
|
|
133
|
+
parseLoginRequest(sp: ServiceProvider, binding: string, req: ESamlHttpRequest) {
|
|
134
|
+
const self = this;
|
|
135
|
+
return flow({
|
|
136
|
+
from: sp,
|
|
137
|
+
self: self,
|
|
138
|
+
checkSignature: self.entityMeta.isWantAuthnRequestsSigned(),
|
|
139
|
+
parserType: 'SAMLRequest',
|
|
140
|
+
type: 'login',
|
|
141
|
+
binding: binding,
|
|
142
|
+
request: req
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
package/src/entity-sp.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file entity-sp.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc Declares the actions taken by service provider
|
|
5
|
+
*/
|
|
6
|
+
import Entity, {
|
|
7
|
+
BindingContext,
|
|
8
|
+
PostBindingContext,
|
|
9
|
+
ESamlHttpRequest,
|
|
10
|
+
SimpleSignBindingContext,
|
|
11
|
+
} from './entity.js';
|
|
12
|
+
import {
|
|
13
|
+
IdentityProviderConstructor as IdentityProvider,
|
|
14
|
+
ServiceProviderMetadata,
|
|
15
|
+
ServiceProviderSettings,
|
|
16
|
+
} from './types.js';
|
|
17
|
+
import { namespace } from './urn.js';
|
|
18
|
+
import redirectBinding from './binding-redirect.js';
|
|
19
|
+
import postBinding from './binding-post.js';
|
|
20
|
+
import simpleSignBinding from './binding-simplesign.js';
|
|
21
|
+
import { flow, FlowResult } from './flow.js';
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* @desc interface function
|
|
25
|
+
*/
|
|
26
|
+
export default function(props: ServiceProviderSettings) {
|
|
27
|
+
return new ServiceProvider(props);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @desc Service provider can be configured using either metadata importing or spSetting
|
|
32
|
+
* @param {object} spSettingimport { FlowResult } from '../types/src/flow.d';
|
|
33
|
+
|
|
34
|
+
*/
|
|
35
|
+
export class ServiceProvider extends Entity {
|
|
36
|
+
declare entityMeta: ServiceProviderMetadata;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @desc Inherited from Entity
|
|
40
|
+
* @param {object} spSetting setting of service provider
|
|
41
|
+
*/
|
|
42
|
+
constructor(spSetting: ServiceProviderSettings) {
|
|
43
|
+
const entitySetting = Object.assign({
|
|
44
|
+
authnRequestsSigned: false,
|
|
45
|
+
wantAssertionsSigned: false,
|
|
46
|
+
wantMessageSigned: false,
|
|
47
|
+
}, spSetting);
|
|
48
|
+
super(entitySetting, 'sp');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @desc Generates the login request for developers to design their own method
|
|
53
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
54
|
+
* @param {string} binding protocol binding
|
|
55
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
56
|
+
*/
|
|
57
|
+
public createLoginRequest(
|
|
58
|
+
idp: IdentityProvider,
|
|
59
|
+
binding = 'redirect',
|
|
60
|
+
customTagReplacement?: (template: string) => BindingContext,
|
|
61
|
+
): BindingContext | PostBindingContext| SimpleSignBindingContext {
|
|
62
|
+
const nsBinding = namespace.binding;
|
|
63
|
+
const protocol = nsBinding[binding];
|
|
64
|
+
if (this.entityMeta.isAuthnRequestSigned() !== idp.entityMeta.isWantAuthnRequestsSigned()) {
|
|
65
|
+
throw new Error('ERR_METADATA_CONFLICT_REQUEST_SIGNED_FLAG');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let context: any = null;
|
|
69
|
+
switch (protocol) {
|
|
70
|
+
case nsBinding.redirect:
|
|
71
|
+
return redirectBinding.loginRequestRedirectURL({ idp, sp: this }, customTagReplacement);
|
|
72
|
+
|
|
73
|
+
case nsBinding.post:
|
|
74
|
+
context = postBinding.base64LoginRequest("/*[local-name(.)='AuthnRequest']", { idp, sp: this }, customTagReplacement);
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case nsBinding.simpleSign:
|
|
78
|
+
// Object context = {id, context, signature, sigAlg}
|
|
79
|
+
context = simpleSignBinding.base64LoginRequest( { idp, sp: this }, customTagReplacement);
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
default:
|
|
83
|
+
// Will support artifact in the next release
|
|
84
|
+
throw new Error('ERR_SP_LOGIN_REQUEST_UNDEFINED_BINDING');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
...context,
|
|
89
|
+
relayState: this.entitySetting.relayState,
|
|
90
|
+
entityEndpoint: idp.entityMeta.getSingleSignOnService(binding) as string,
|
|
91
|
+
type: 'SAMLRequest',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @desc Validation of the parsed the URL parameters
|
|
97
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
98
|
+
* @param {string} binding protocol binding
|
|
99
|
+
* @param {request} req request
|
|
100
|
+
*/
|
|
101
|
+
public parseLoginResponse(idp, binding, request: ESamlHttpRequest) {
|
|
102
|
+
const self = this;
|
|
103
|
+
return flow({
|
|
104
|
+
from: idp,
|
|
105
|
+
self: self,
|
|
106
|
+
checkSignature: true, // saml response must have signature
|
|
107
|
+
parserType: 'SAMLResponse',
|
|
108
|
+
type: 'login',
|
|
109
|
+
binding: binding,
|
|
110
|
+
request: request
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
package/src/entity.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file entity.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc An abstraction for identity provider and service provider.
|
|
5
|
+
*/
|
|
6
|
+
import { isString, isNonEmptyArray } from './utility.js';
|
|
7
|
+
import { namespace, wording, algorithms, messageConfigurations } from './urn.js';
|
|
8
|
+
import * as uuid from 'uuid';
|
|
9
|
+
import IdpMetadata, { IdpMetadata as IdpMetadataConstructor } from './metadata-idp.js';
|
|
10
|
+
import SpMetadata, { SpMetadata as SpMetadataConstructor } from './metadata-sp.js';
|
|
11
|
+
import redirectBinding from './binding-redirect.js';
|
|
12
|
+
import postBinding from './binding-post.js';
|
|
13
|
+
import { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting } from './types.js';
|
|
14
|
+
import { flow, FlowResult } from './flow.js';
|
|
15
|
+
|
|
16
|
+
const dataEncryptionAlgorithm = algorithms.encryption.data;
|
|
17
|
+
const keyEncryptionAlgorithm = algorithms.encryption.key;
|
|
18
|
+
const signatureAlgorithms = algorithms.signature;
|
|
19
|
+
const messageSigningOrders = messageConfigurations.signingOrder;
|
|
20
|
+
|
|
21
|
+
const defaultEntitySetting = {
|
|
22
|
+
wantLogoutResponseSigned: false,
|
|
23
|
+
messageSigningOrder: messageSigningOrders.SIGN_THEN_ENCRYPT,
|
|
24
|
+
wantLogoutRequestSigned: false,
|
|
25
|
+
allowCreate: false,
|
|
26
|
+
isAssertionEncrypted: false,
|
|
27
|
+
requestSignatureAlgorithm: signatureAlgorithms.RSA_SHA512,
|
|
28
|
+
dataEncryptionAlgorithm: dataEncryptionAlgorithm.AES_256_GCM,
|
|
29
|
+
keyEncryptionAlgorithm: keyEncryptionAlgorithm.RSA_OAEP_MGF1P,
|
|
30
|
+
generateID: (): string => ('_' + uuid.v4()),
|
|
31
|
+
relayState: '',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface ESamlHttpRequest {
|
|
35
|
+
query?: any;
|
|
36
|
+
body?: any;
|
|
37
|
+
octetString?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface BindingContext {
|
|
41
|
+
context: string;
|
|
42
|
+
id: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PostBindingContext extends BindingContext {
|
|
46
|
+
relayState?: string;
|
|
47
|
+
entityEndpoint: string;
|
|
48
|
+
type: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SimpleSignBindingContext extends PostBindingContext {
|
|
52
|
+
sigAlg?: string;
|
|
53
|
+
signature?: string;
|
|
54
|
+
keyInfo?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SimpleSignComputedContext extends BindingContext {
|
|
58
|
+
sigAlg?: string;
|
|
59
|
+
signature?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ParseResult {
|
|
63
|
+
samlContent: string;
|
|
64
|
+
extract: any;
|
|
65
|
+
sigAlg: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type EntityConstructor = (MetadataIdpConstructor | MetadataSpConstructor)
|
|
69
|
+
& { metadata?: string | Buffer };
|
|
70
|
+
|
|
71
|
+
export default class Entity {
|
|
72
|
+
entitySetting: EntitySetting;
|
|
73
|
+
entityType: string;
|
|
74
|
+
entityMeta: IdpMetadataConstructor | SpMetadataConstructor;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param entitySetting
|
|
78
|
+
* @param entityMeta is the entity metadata, deprecated after 2.0
|
|
79
|
+
*/
|
|
80
|
+
constructor(entitySetting: EntityConstructor, entityType: 'idp' | 'sp') {
|
|
81
|
+
this.entitySetting = Object.assign({}, defaultEntitySetting, entitySetting);
|
|
82
|
+
const metadata = entitySetting.metadata || entitySetting;
|
|
83
|
+
switch (entityType) {
|
|
84
|
+
case 'idp':
|
|
85
|
+
this.entityMeta = IdpMetadata(metadata);
|
|
86
|
+
// setting with metadata has higher precedence
|
|
87
|
+
this.entitySetting.wantAuthnRequestsSigned = this.entityMeta.isWantAuthnRequestsSigned();
|
|
88
|
+
this.entitySetting.nameIDFormat = this.entityMeta.getNameIDFormat() || this.entitySetting.nameIDFormat;
|
|
89
|
+
break;
|
|
90
|
+
case 'sp':
|
|
91
|
+
this.entityMeta = SpMetadata(metadata);
|
|
92
|
+
// setting with metadata has higher precedence
|
|
93
|
+
this.entitySetting.authnRequestsSigned = this.entityMeta.isAuthnRequestSigned();
|
|
94
|
+
this.entitySetting.wantAssertionsSigned = this.entityMeta.isWantAssertionsSigned();
|
|
95
|
+
this.entitySetting.nameIDFormat = this.entityMeta.getNameIDFormat() || this.entitySetting.nameIDFormat;
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
throw new Error('ERR_UNDEFINED_ENTITY_TYPE');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @desc Returns the setting of entity
|
|
104
|
+
* @return {object}
|
|
105
|
+
*/
|
|
106
|
+
getEntitySetting() {
|
|
107
|
+
return this.entitySetting;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @desc Returns the xml string of entity metadata
|
|
111
|
+
* @return {string}
|
|
112
|
+
*/
|
|
113
|
+
getMetadata(): string {
|
|
114
|
+
return this.entityMeta.getMetadata();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @desc Exports the entity metadata into specified folder
|
|
119
|
+
* @param {string} exportFile indicates the file name
|
|
120
|
+
*/
|
|
121
|
+
exportMetadata(exportFile: string) {
|
|
122
|
+
return this.entityMeta.exportMetadata(exportFile);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** * @desc Verify fields with the one specified in metadata
|
|
126
|
+
* @param {string/[string]} field is a string or an array of string indicating the field value in SAML message
|
|
127
|
+
* @param {string} metaField is a string indicating the same field specified in metadata
|
|
128
|
+
* @return {boolean} True/False
|
|
129
|
+
*/
|
|
130
|
+
verifyFields(field: string | string[], metaField: string): boolean {
|
|
131
|
+
if (isString(field)) {
|
|
132
|
+
return field === metaField;
|
|
133
|
+
}
|
|
134
|
+
if (isNonEmptyArray(field)) {
|
|
135
|
+
let res = true;
|
|
136
|
+
(field as string[]).forEach(f => {
|
|
137
|
+
if (f !== metaField) {
|
|
138
|
+
res = false;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return res;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
/** @desc Generates the logout request for developers to design their own method
|
|
147
|
+
* @param {ServiceProvider} sp object of service provider
|
|
148
|
+
* @param {string} binding protocol binding
|
|
149
|
+
* @param {object} user current logged user (e.g. user)
|
|
150
|
+
* @param {string} relayState the URL to which to redirect the user when logout is complete
|
|
151
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
152
|
+
*/
|
|
153
|
+
createLogoutRequest(targetEntity, binding, user, relayState = '', customTagReplacement?): BindingContext | PostBindingContext {
|
|
154
|
+
if (binding === wording.binding.redirect) {
|
|
155
|
+
return redirectBinding.logoutRequestRedirectURL(user, {
|
|
156
|
+
init: this,
|
|
157
|
+
target: targetEntity,
|
|
158
|
+
}, relayState, customTagReplacement);
|
|
159
|
+
}
|
|
160
|
+
if (binding === wording.binding.post) {
|
|
161
|
+
const entityEndpoint = targetEntity.entityMeta.getSingleLogoutService(binding);
|
|
162
|
+
const context = postBinding.base64LogoutRequest(user, "/*[local-name(.)='LogoutRequest']", { init: this, target: targetEntity }, customTagReplacement);
|
|
163
|
+
return {
|
|
164
|
+
...context,
|
|
165
|
+
relayState,
|
|
166
|
+
entityEndpoint,
|
|
167
|
+
type: 'SAMLRequest',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// Will support artifact in the next release
|
|
171
|
+
throw new Error('ERR_UNDEFINED_BINDING');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @desc Generates the logout response for developers to design their own method
|
|
176
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
177
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
178
|
+
* @param {string} relayState the URL to which to redirect the user when logout is complete.
|
|
179
|
+
* @param {string} binding protocol binding
|
|
180
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
181
|
+
*/
|
|
182
|
+
createLogoutResponse(target, requestInfo, binding, relayState = '', customTagReplacement?): BindingContext | PostBindingContext {
|
|
183
|
+
const protocol = namespace.binding[binding];
|
|
184
|
+
if (protocol === namespace.binding.redirect) {
|
|
185
|
+
return redirectBinding.logoutResponseRedirectURL(requestInfo, {
|
|
186
|
+
init: this,
|
|
187
|
+
target,
|
|
188
|
+
}, relayState, customTagReplacement);
|
|
189
|
+
}
|
|
190
|
+
if (protocol === namespace.binding.post) {
|
|
191
|
+
const context = postBinding.base64LogoutResponse(requestInfo, {
|
|
192
|
+
init: this,
|
|
193
|
+
target,
|
|
194
|
+
}, customTagReplacement);
|
|
195
|
+
return {
|
|
196
|
+
...context,
|
|
197
|
+
relayState,
|
|
198
|
+
entityEndpoint: target.entityMeta.getSingleLogoutService(binding),
|
|
199
|
+
type: 'SAMLResponse',
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
throw new Error('ERR_CREATE_LOGOUT_RESPONSE_UNDEFINED_BINDING');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @desc Validation of the parsed the URL parameters
|
|
207
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
208
|
+
* @param {string} binding protocol binding
|
|
209
|
+
* @param {request} req request
|
|
210
|
+
* @return {Promise}
|
|
211
|
+
*/
|
|
212
|
+
parseLogoutRequest(from, binding, request: ESamlHttpRequest) {
|
|
213
|
+
const self = this;
|
|
214
|
+
return flow({
|
|
215
|
+
from: from,
|
|
216
|
+
self: self,
|
|
217
|
+
type: 'logout',
|
|
218
|
+
parserType: 'LogoutRequest',
|
|
219
|
+
checkSignature: this.entitySetting.wantLogoutRequestSigned,
|
|
220
|
+
binding: binding,
|
|
221
|
+
request: request,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @desc Validation of the parsed the URL parameters
|
|
226
|
+
* @param {object} config config for the parser
|
|
227
|
+
* @param {string} binding protocol binding
|
|
228
|
+
* @param {request} req request
|
|
229
|
+
* @return {Promise}
|
|
230
|
+
*/
|
|
231
|
+
parseLogoutResponse(from, binding, request: ESamlHttpRequest) {
|
|
232
|
+
const self = this;
|
|
233
|
+
return flow({
|
|
234
|
+
from: from,
|
|
235
|
+
self: self,
|
|
236
|
+
type: 'logout',
|
|
237
|
+
parserType: 'LogoutResponse',
|
|
238
|
+
checkSignature: self.entitySetting.wantLogoutResponseSigned,
|
|
239
|
+
binding: binding,
|
|
240
|
+
request: request
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|