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
package/tslint.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "tslint:recommended",
|
|
3
|
+
"rulesDirectory": [],
|
|
4
|
+
"linterOptions": {
|
|
5
|
+
"exclude": [
|
|
6
|
+
"node_modules/**"
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"rules": {
|
|
10
|
+
"arrow-parens": [true, "ban-single-arg-parens"],
|
|
11
|
+
"comment-format": false,
|
|
12
|
+
"interface-name": [true, "never-prefix"],
|
|
13
|
+
"jsdoc-format": false,
|
|
14
|
+
"max-line-length": false,
|
|
15
|
+
"member-access": false,
|
|
16
|
+
"no-console": [false],
|
|
17
|
+
"no-consecutive-blank-lines": [true, 3],
|
|
18
|
+
"no-empty-interface": false,
|
|
19
|
+
"no-string-literal": false,
|
|
20
|
+
"object-literal-sort-keys": false,
|
|
21
|
+
"object-literal-key-quotes": false,
|
|
22
|
+
"object-literal-shorthand": false,
|
|
23
|
+
"trailing-comma": false,
|
|
24
|
+
"eofline": false,
|
|
25
|
+
"no-empty": false,
|
|
26
|
+
"align": false,
|
|
27
|
+
"no-trailing-whitespace": false,
|
|
28
|
+
"ordered-imports": false,
|
|
29
|
+
"quotemark": [true, "single", "avoid-escape", "avoid-template"],
|
|
30
|
+
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
|
31
|
+
"interface-over-type-literal": false,
|
|
32
|
+
"no-var-requires": false
|
|
33
|
+
},
|
|
34
|
+
"jsRules": {}
|
|
35
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import IdentityProvider, { IdentityProvider as IdentityProviderInstance } from './src/entity-idp.js';
|
|
2
|
+
import ServiceProvider, { ServiceProvider as ServiceProviderInstance } from './src/entity-sp.js';
|
|
3
|
+
export { default as IdPMetadata } from './src/metadata-idp.js';
|
|
4
|
+
export { default as SPMetadata } from './src/metadata-sp.js';
|
|
5
|
+
export { default as Utility } from './src/utility.js';
|
|
6
|
+
export { default as SamlLib } from './src/libsaml.js';
|
|
7
|
+
import * as Constants from './src/urn.js';
|
|
8
|
+
import * as Extractor from './src/extractor.js';
|
|
9
|
+
import { setSchemaValidator, setDOMParserOptions } from './src/api.js';
|
|
10
|
+
export { Constants, Extractor, IdentityProvider, IdentityProviderInstance, ServiceProvider, ServiceProviderInstance, setSchemaValidator, setDOMParserOptions };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DOMParser as dom, Options as DOMParserOptions } from '@xmldom/xmldom';
|
|
2
|
+
interface Context extends ValidatorContext, DOMParserContext {
|
|
3
|
+
}
|
|
4
|
+
interface ValidatorContext {
|
|
5
|
+
validate?: (xml: string) => Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
interface DOMParserContext {
|
|
8
|
+
dom: dom;
|
|
9
|
+
}
|
|
10
|
+
export declare function getContext(): Context;
|
|
11
|
+
export declare function setSchemaValidator(params: ValidatorContext): void;
|
|
12
|
+
export declare function setDOMParserOptions(options?: DOMParserOptions): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file binding-post.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc Binding-level API, declare the functions using POST binding
|
|
5
|
+
*/
|
|
6
|
+
import { BindingContext } from './entity.js';
|
|
7
|
+
/**
|
|
8
|
+
* @desc Generate a base64 encoded login request
|
|
9
|
+
* @param {string} referenceTagXPath reference uri
|
|
10
|
+
* @param {object} entity object includes both idp and sp
|
|
11
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
12
|
+
*/
|
|
13
|
+
declare function base64LoginRequest(referenceTagXPath: string, entity: any, customTagReplacement?: (template: string) => BindingContext): BindingContext;
|
|
14
|
+
/**
|
|
15
|
+
* @desc Generate a base64 encoded login response
|
|
16
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
17
|
+
* @param {object} entity object includes both idp and sp
|
|
18
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
19
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
20
|
+
* @param {boolean} encryptThenSign whether or not to encrypt then sign first (if signing). Defaults to sign-then-encrypt
|
|
21
|
+
*/
|
|
22
|
+
declare function base64LoginResponse(requestInfo: any | undefined, entity: any, user?: any, customTagReplacement?: (template: string) => BindingContext, encryptThenSign?: boolean): Promise<BindingContext>;
|
|
23
|
+
/**
|
|
24
|
+
* @desc Generate a base64 encoded logout request
|
|
25
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
26
|
+
* @param {string} referenceTagXPath reference uri
|
|
27
|
+
* @param {object} entity object includes both idp and sp
|
|
28
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
29
|
+
* @return {string} base64 encoded request
|
|
30
|
+
*/
|
|
31
|
+
declare function base64LogoutRequest(user: any, referenceTagXPath: any, entity: any, customTagReplacement?: (template: string) => BindingContext): BindingContext;
|
|
32
|
+
/**
|
|
33
|
+
* @desc Generate a base64 encoded logout response
|
|
34
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
35
|
+
* @param {string} referenceTagXPath reference uri
|
|
36
|
+
* @param {object} entity object includes both idp and sp
|
|
37
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
38
|
+
*/
|
|
39
|
+
declare function base64LogoutResponse(requestInfo: any, entity: any, customTagReplacement: (template: string) => BindingContext): BindingContext;
|
|
40
|
+
declare const postBinding: {
|
|
41
|
+
base64LoginRequest: typeof base64LoginRequest;
|
|
42
|
+
base64LoginResponse: typeof base64LoginResponse;
|
|
43
|
+
base64LogoutRequest: typeof base64LogoutRequest;
|
|
44
|
+
base64LogoutResponse: typeof base64LogoutResponse;
|
|
45
|
+
};
|
|
46
|
+
export default postBinding;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BindingContext } from './entity.js';
|
|
2
|
+
import { IdentityProvider as Idp } from './entity-idp.js';
|
|
3
|
+
import { ServiceProvider as Sp } from './entity-sp.js';
|
|
4
|
+
export interface BuildRedirectConfig {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
type: string;
|
|
7
|
+
isSigned: boolean;
|
|
8
|
+
context: string;
|
|
9
|
+
entitySetting: any;
|
|
10
|
+
relayState?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @desc Redirect URL for login request
|
|
14
|
+
* @param {object} entity object includes both idp and sp
|
|
15
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
16
|
+
* @return {string} redirect URL
|
|
17
|
+
*/
|
|
18
|
+
declare function loginRequestRedirectURL(entity: {
|
|
19
|
+
idp: Idp;
|
|
20
|
+
sp: Sp;
|
|
21
|
+
}, customTagReplacement?: (template: string) => BindingContext): BindingContext;
|
|
22
|
+
/**
|
|
23
|
+
* @desc Redirect URL for login response
|
|
24
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
25
|
+
* @param {object} entity object includes both idp and sp
|
|
26
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
27
|
+
* @param {String} relayState the relaystate sent by sp corresponding request
|
|
28
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
29
|
+
*/
|
|
30
|
+
declare function loginResponseRedirectURL(requestInfo: any, entity: any, user?: any, relayState?: string, customTagReplacement?: (template: string) => BindingContext): BindingContext;
|
|
31
|
+
/**
|
|
32
|
+
* @desc Redirect URL for logout request
|
|
33
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
34
|
+
* @param {object} entity object includes both idp and sp
|
|
35
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
36
|
+
* @return {string} redirect URL
|
|
37
|
+
*/
|
|
38
|
+
declare function logoutRequestRedirectURL(user: any, entity: any, relayState?: string, customTagReplacement?: (template: string, tags: object) => BindingContext): BindingContext;
|
|
39
|
+
/**
|
|
40
|
+
* @desc Redirect URL for logout response
|
|
41
|
+
* @param {object} requescorresponding request, used to obtain the id
|
|
42
|
+
* @param {object} entity object includes both idp and sp
|
|
43
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
44
|
+
*/
|
|
45
|
+
declare function logoutResponseRedirectURL(requestInfo: any, entity: any, relayState?: string, customTagReplacement?: (template: string) => BindingContext): BindingContext;
|
|
46
|
+
declare const redirectBinding: {
|
|
47
|
+
loginRequestRedirectURL: typeof loginRequestRedirectURL;
|
|
48
|
+
loginResponseRedirectURL: typeof loginResponseRedirectURL;
|
|
49
|
+
logoutRequestRedirectURL: typeof logoutRequestRedirectURL;
|
|
50
|
+
logoutResponseRedirectURL: typeof logoutResponseRedirectURL;
|
|
51
|
+
};
|
|
52
|
+
export default redirectBinding;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file binding-simplesign.ts
|
|
3
|
+
* @author Orange
|
|
4
|
+
* @desc Binding-level API, declare the functions using POST SimpleSign binding
|
|
5
|
+
*/
|
|
6
|
+
import { BindingContext, SimpleSignComputedContext } from './entity.js';
|
|
7
|
+
export interface BuildSimpleSignConfig {
|
|
8
|
+
type: string;
|
|
9
|
+
context: string;
|
|
10
|
+
entitySetting: any;
|
|
11
|
+
relayState?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BindingSimpleSignContext {
|
|
14
|
+
id: string;
|
|
15
|
+
context: string;
|
|
16
|
+
signature: any;
|
|
17
|
+
sigAlg: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @desc Generate a base64 encoded login request
|
|
21
|
+
* @param {string} referenceTagXPath reference uri
|
|
22
|
+
* @param {object} entity object includes both idp and sp
|
|
23
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
24
|
+
*/
|
|
25
|
+
declare function base64LoginRequest(entity: any, customTagReplacement?: (template: string) => BindingContext): SimpleSignComputedContext;
|
|
26
|
+
/**
|
|
27
|
+
* @desc Generate a base64 encoded login response
|
|
28
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
29
|
+
* @param {object} entity object includes both idp and sp
|
|
30
|
+
* @param {object} user current logged user (e.g. req.user)
|
|
31
|
+
* @param {string} relayState the relay state
|
|
32
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
33
|
+
*/
|
|
34
|
+
declare function base64LoginResponse(requestInfo: any | undefined, entity: any, user?: any, relayState?: string, customTagReplacement?: (template: string) => BindingContext): Promise<BindingSimpleSignContext>;
|
|
35
|
+
declare const simpleSignBinding: {
|
|
36
|
+
base64LoginRequest: typeof base64LoginRequest;
|
|
37
|
+
base64LoginResponse: typeof base64LoginResponse;
|
|
38
|
+
};
|
|
39
|
+
export default simpleSignBinding;
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { ServiceProviderConstructor as ServiceProvider, IdentityProviderMetadata, IdentityProviderSettings } from './types.js';
|
|
8
|
+
import { FlowResult } from './flow.js';
|
|
9
|
+
import { BindingContext } from './entity.js';
|
|
10
|
+
/**
|
|
11
|
+
* Identity provider can be configured using either metadata importing or idpSetting
|
|
12
|
+
*/
|
|
13
|
+
export default function (props: IdentityProviderSettings): IdentityProvider;
|
|
14
|
+
/**
|
|
15
|
+
* Identity provider can be configured using either metadata importing or idpSetting
|
|
16
|
+
*/
|
|
17
|
+
export declare class IdentityProvider extends Entity {
|
|
18
|
+
entityMeta: IdentityProviderMetadata;
|
|
19
|
+
constructor(idpSetting: IdentityProviderSettings);
|
|
20
|
+
/**
|
|
21
|
+
* @desc Generates the login response for developers to design their own method
|
|
22
|
+
* @param sp object of service provider
|
|
23
|
+
* @param requestInfo corresponding request, used to obtain the id
|
|
24
|
+
* @param binding protocol binding
|
|
25
|
+
* @param user current logged user (e.g. req.user)
|
|
26
|
+
* @param customTagReplacement used when developers have their own login response template
|
|
27
|
+
* @param encryptThenSign whether or not to encrypt then sign first (if signing)
|
|
28
|
+
* @param relayState the relayState from corresponding request
|
|
29
|
+
*/
|
|
30
|
+
createLoginResponse(sp: ServiceProvider, requestInfo: {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}, binding: string, user: {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}, customTagReplacement?: (template: string) => BindingContext, encryptThenSign?: boolean, relayState?: string): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Validation of the parsed URL parameters
|
|
37
|
+
* @param sp ServiceProvider instance
|
|
38
|
+
* @param binding Protocol binding
|
|
39
|
+
* @param req RequesmessageSigningOrderst
|
|
40
|
+
*/
|
|
41
|
+
parseLoginRequest(sp: ServiceProvider, binding: string, req: ESamlHttpRequest): Promise<FlowResult>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file entity-sp.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc Declares the actions taken by service provider
|
|
5
|
+
*/
|
|
6
|
+
import Entity, { BindingContext, PostBindingContext, ESamlHttpRequest, SimpleSignBindingContext } from './entity.js';
|
|
7
|
+
import { IdentityProviderConstructor as IdentityProvider, ServiceProviderMetadata, ServiceProviderSettings } from './types.js';
|
|
8
|
+
import { FlowResult } from './flow.js';
|
|
9
|
+
export default function (props: ServiceProviderSettings): ServiceProvider;
|
|
10
|
+
/**
|
|
11
|
+
* @desc Service provider can be configured using either metadata importing or spSetting
|
|
12
|
+
* @param {object} spSettingimport { FlowResult } from '../types/src/flow.d';
|
|
13
|
+
|
|
14
|
+
*/
|
|
15
|
+
export declare class ServiceProvider extends Entity {
|
|
16
|
+
entityMeta: ServiceProviderMetadata;
|
|
17
|
+
/**
|
|
18
|
+
* @desc Inherited from Entity
|
|
19
|
+
* @param {object} spSetting setting of service provider
|
|
20
|
+
*/
|
|
21
|
+
constructor(spSetting: ServiceProviderSettings);
|
|
22
|
+
/**
|
|
23
|
+
* @desc Generates the login request for developers to design their own method
|
|
24
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
25
|
+
* @param {string} binding protocol binding
|
|
26
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
27
|
+
*/
|
|
28
|
+
createLoginRequest(idp: IdentityProvider, binding?: string, customTagReplacement?: (template: string) => BindingContext): BindingContext | PostBindingContext | SimpleSignBindingContext;
|
|
29
|
+
/**
|
|
30
|
+
* @desc Validation of the parsed the URL parameters
|
|
31
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
32
|
+
* @param {string} binding protocol binding
|
|
33
|
+
* @param {request} req request
|
|
34
|
+
*/
|
|
35
|
+
parseLoginResponse(idp: any, binding: any, request: ESamlHttpRequest): Promise<FlowResult>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { IdpMetadata as IdpMetadataConstructor } from './metadata-idp.js';
|
|
2
|
+
import { SpMetadata as SpMetadataConstructor } from './metadata-sp.js';
|
|
3
|
+
import { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting } from './types.js';
|
|
4
|
+
import { FlowResult } from './flow.js';
|
|
5
|
+
export interface ESamlHttpRequest {
|
|
6
|
+
query?: any;
|
|
7
|
+
body?: any;
|
|
8
|
+
octetString?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BindingContext {
|
|
11
|
+
context: string;
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PostBindingContext extends BindingContext {
|
|
15
|
+
relayState?: string;
|
|
16
|
+
entityEndpoint: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SimpleSignBindingContext extends PostBindingContext {
|
|
20
|
+
sigAlg?: string;
|
|
21
|
+
signature?: string;
|
|
22
|
+
keyInfo?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SimpleSignComputedContext extends BindingContext {
|
|
25
|
+
sigAlg?: string;
|
|
26
|
+
signature?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ParseResult {
|
|
29
|
+
samlContent: string;
|
|
30
|
+
extract: any;
|
|
31
|
+
sigAlg: string;
|
|
32
|
+
}
|
|
33
|
+
export type EntityConstructor = (MetadataIdpConstructor | MetadataSpConstructor) & {
|
|
34
|
+
metadata?: string | Buffer;
|
|
35
|
+
};
|
|
36
|
+
export default class Entity {
|
|
37
|
+
entitySetting: EntitySetting;
|
|
38
|
+
entityType: string;
|
|
39
|
+
entityMeta: IdpMetadataConstructor | SpMetadataConstructor;
|
|
40
|
+
/**
|
|
41
|
+
* @param entitySetting
|
|
42
|
+
* @param entityMeta is the entity metadata, deprecated after 2.0
|
|
43
|
+
*/
|
|
44
|
+
constructor(entitySetting: EntityConstructor, entityType: 'idp' | 'sp');
|
|
45
|
+
/**
|
|
46
|
+
* @desc Returns the setting of entity
|
|
47
|
+
* @return {object}
|
|
48
|
+
*/
|
|
49
|
+
getEntitySetting(): EntitySetting;
|
|
50
|
+
/**
|
|
51
|
+
* @desc Returns the xml string of entity metadata
|
|
52
|
+
* @return {string}
|
|
53
|
+
*/
|
|
54
|
+
getMetadata(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @desc Exports the entity metadata into specified folder
|
|
57
|
+
* @param {string} exportFile indicates the file name
|
|
58
|
+
*/
|
|
59
|
+
exportMetadata(exportFile: string): void;
|
|
60
|
+
/** * @desc Verify fields with the one specified in metadata
|
|
61
|
+
* @param {string/[string]} field is a string or an array of string indicating the field value in SAML message
|
|
62
|
+
* @param {string} metaField is a string indicating the same field specified in metadata
|
|
63
|
+
* @return {boolean} True/False
|
|
64
|
+
*/
|
|
65
|
+
verifyFields(field: string | string[], metaField: string): boolean;
|
|
66
|
+
/** @desc Generates the logout request for developers to design their own method
|
|
67
|
+
* @param {ServiceProvider} sp object of service provider
|
|
68
|
+
* @param {string} binding protocol binding
|
|
69
|
+
* @param {object} user current logged user (e.g. user)
|
|
70
|
+
* @param {string} relayState the URL to which to redirect the user when logout is complete
|
|
71
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
72
|
+
*/
|
|
73
|
+
createLogoutRequest(targetEntity: any, binding: any, user: any, relayState?: string, customTagReplacement?: any): BindingContext | PostBindingContext;
|
|
74
|
+
/**
|
|
75
|
+
* @desc Generates the logout response for developers to design their own method
|
|
76
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
77
|
+
* @param {object} requestInfo corresponding request, used to obtain the id
|
|
78
|
+
* @param {string} relayState the URL to which to redirect the user when logout is complete.
|
|
79
|
+
* @param {string} binding protocol binding
|
|
80
|
+
* @param {function} customTagReplacement used when developers have their own login response template
|
|
81
|
+
*/
|
|
82
|
+
createLogoutResponse(target: any, requestInfo: any, binding: any, relayState?: string, customTagReplacement?: any): BindingContext | PostBindingContext;
|
|
83
|
+
/**
|
|
84
|
+
* @desc Validation of the parsed the URL parameters
|
|
85
|
+
* @param {IdentityProvider} idp object of identity provider
|
|
86
|
+
* @param {string} binding protocol binding
|
|
87
|
+
* @param {request} req request
|
|
88
|
+
* @return {Promise}
|
|
89
|
+
*/
|
|
90
|
+
parseLogoutRequest(from: any, binding: any, request: ESamlHttpRequest): Promise<FlowResult>;
|
|
91
|
+
/**
|
|
92
|
+
* @desc Validation of the parsed the URL parameters
|
|
93
|
+
* @param {object} config config for the parser
|
|
94
|
+
* @param {string} binding protocol binding
|
|
95
|
+
* @param {request} req request
|
|
96
|
+
* @return {Promise}
|
|
97
|
+
*/
|
|
98
|
+
parseLogoutResponse(from: any, binding: any, request: ESamlHttpRequest): Promise<FlowResult>;
|
|
99
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface ExtractorField {
|
|
2
|
+
key: string;
|
|
3
|
+
localPath: string[] | string[][];
|
|
4
|
+
attributes: string[];
|
|
5
|
+
index?: string[];
|
|
6
|
+
attributePath?: string[];
|
|
7
|
+
context?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type ExtractorFields = ExtractorField[];
|
|
10
|
+
export declare const loginRequestFields: ExtractorFields;
|
|
11
|
+
export declare const loginResponseStatusFields: {
|
|
12
|
+
key: string;
|
|
13
|
+
localPath: string[];
|
|
14
|
+
attributes: string[];
|
|
15
|
+
}[];
|
|
16
|
+
export declare const logoutResponseStatusFields: {
|
|
17
|
+
key: string;
|
|
18
|
+
localPath: string[];
|
|
19
|
+
attributes: string[];
|
|
20
|
+
}[];
|
|
21
|
+
export declare const loginResponseFields: ((assertion: any) => ExtractorFields);
|
|
22
|
+
export declare const logoutRequestFields: ExtractorFields;
|
|
23
|
+
export declare const logoutResponseFields: ExtractorFields;
|
|
24
|
+
export declare function extract(context: string, fields: any): any;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SamlLib.js
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc A simple library including some common functions
|
|
5
|
+
*/
|
|
6
|
+
import { MetadataInterface } from './metadata.js';
|
|
7
|
+
export interface SignatureConstructor {
|
|
8
|
+
rawSamlMessage: string;
|
|
9
|
+
referenceTagXPath?: string;
|
|
10
|
+
privateKey: string;
|
|
11
|
+
privateKeyPass?: string;
|
|
12
|
+
signatureAlgorithm: string;
|
|
13
|
+
signingCert: string | Buffer;
|
|
14
|
+
isBase64Output?: boolean;
|
|
15
|
+
signatureConfig?: any;
|
|
16
|
+
isMessageSigned?: boolean;
|
|
17
|
+
transformationAlgorithms?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface SignatureVerifierOptions {
|
|
20
|
+
metadata?: MetadataInterface;
|
|
21
|
+
keyFile?: string;
|
|
22
|
+
signatureAlgorithm?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ExtractorResult {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
signature?: string | string[];
|
|
27
|
+
issuer?: string | string[];
|
|
28
|
+
nameID?: string;
|
|
29
|
+
notexist?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface LoginResponseAttribute {
|
|
32
|
+
name: string;
|
|
33
|
+
nameFormat: string;
|
|
34
|
+
valueXsiType: string;
|
|
35
|
+
valueTag: string;
|
|
36
|
+
valueXmlnsXs?: string;
|
|
37
|
+
valueXmlnsXsi?: string;
|
|
38
|
+
type?: string | string[];
|
|
39
|
+
}
|
|
40
|
+
export interface LoginResponseAdditionalTemplates {
|
|
41
|
+
attributeStatementTemplate?: AttributeStatementTemplate;
|
|
42
|
+
attributeTemplate?: AttributeTemplate;
|
|
43
|
+
}
|
|
44
|
+
export interface BaseSamlTemplate {
|
|
45
|
+
context: string;
|
|
46
|
+
}
|
|
47
|
+
export interface LoginResponseTemplate extends BaseSamlTemplate {
|
|
48
|
+
attributes?: LoginResponseAttribute[];
|
|
49
|
+
additionalTemplates?: LoginResponseAdditionalTemplates;
|
|
50
|
+
}
|
|
51
|
+
export interface AttributeStatementTemplate extends BaseSamlTemplate {
|
|
52
|
+
}
|
|
53
|
+
export interface AttributeTemplate extends BaseSamlTemplate {
|
|
54
|
+
}
|
|
55
|
+
export interface LoginRequestTemplate extends BaseSamlTemplate {
|
|
56
|
+
}
|
|
57
|
+
export interface LogoutRequestTemplate extends BaseSamlTemplate {
|
|
58
|
+
}
|
|
59
|
+
export interface LogoutResponseTemplate extends BaseSamlTemplate {
|
|
60
|
+
}
|
|
61
|
+
export type KeyUse = 'signing' | 'encryption';
|
|
62
|
+
export interface KeyComponent {
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
}
|
|
65
|
+
export interface LibSamlInterface {
|
|
66
|
+
getQueryParamByType: (type: string) => string;
|
|
67
|
+
createXPath: (local: any, isExtractAll?: boolean) => string;
|
|
68
|
+
replaceTagsByValue: (rawXML: string, tagValues: any) => string;
|
|
69
|
+
attributeStatementBuilder: (attributes: LoginResponseAttribute[], attributeTemplate: AttributeTemplate, attributeStatementTemplate: AttributeStatementTemplate) => string;
|
|
70
|
+
constructSAMLSignature: (opts: SignatureConstructor) => string;
|
|
71
|
+
verifySignature: (xml: string, opts: SignatureVerifierOptions) => [boolean, any];
|
|
72
|
+
createKeySection: (use: KeyUse, cert: string | Buffer) => {};
|
|
73
|
+
constructMessageSignature: (octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string) => string;
|
|
74
|
+
verifyMessageSignature: (metadata: any, octetString: string, signature: string | Buffer, verifyAlgorithm?: string) => boolean;
|
|
75
|
+
getKeyInfo: (x509Certificate: string, signatureConfig?: any) => void;
|
|
76
|
+
encryptAssertion: (sourceEntity: any, targetEntity: any, entireXML: string) => Promise<string>;
|
|
77
|
+
decryptAssertion: (here: any, entireXML: string) => Promise<[string, any]>;
|
|
78
|
+
getSigningScheme: (sigAlg: string) => string | null;
|
|
79
|
+
getDigestMethod: (sigAlg: string) => string | null;
|
|
80
|
+
nrsaAliasMapping: any;
|
|
81
|
+
defaultLoginRequestTemplate: LoginRequestTemplate;
|
|
82
|
+
defaultLoginResponseTemplate: LoginResponseTemplate;
|
|
83
|
+
defaultAttributeStatementTemplate: AttributeStatementTemplate;
|
|
84
|
+
defaultAttributeTemplate: AttributeTemplate;
|
|
85
|
+
defaultLogoutRequestTemplate: LogoutRequestTemplate;
|
|
86
|
+
defaultLogoutResponseTemplate: LogoutResponseTemplate;
|
|
87
|
+
}
|
|
88
|
+
declare const _default: {
|
|
89
|
+
createXPath: (local: any, isExtractAll?: boolean) => string;
|
|
90
|
+
getQueryParamByType: (type: string) => "SAMLRequest" | "SAMLResponse";
|
|
91
|
+
defaultLoginRequestTemplate: {
|
|
92
|
+
context: string;
|
|
93
|
+
};
|
|
94
|
+
defaultLoginResponseTemplate: {
|
|
95
|
+
context: string;
|
|
96
|
+
attributes: never[];
|
|
97
|
+
additionalTemplates: {
|
|
98
|
+
attributeStatementTemplate: {
|
|
99
|
+
context: string;
|
|
100
|
+
};
|
|
101
|
+
attributeTemplate: {
|
|
102
|
+
context: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
defaultAttributeStatementTemplate: {
|
|
107
|
+
context: string;
|
|
108
|
+
};
|
|
109
|
+
defaultAttributeTemplate: {
|
|
110
|
+
context: string;
|
|
111
|
+
};
|
|
112
|
+
defaultLogoutRequestTemplate: {
|
|
113
|
+
context: string;
|
|
114
|
+
};
|
|
115
|
+
defaultLogoutResponseTemplate: {
|
|
116
|
+
context: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* @desc Replace the tag (e.g. {tag}) inside the raw XML
|
|
120
|
+
* @param {string} rawXML raw XML string used to do keyword replacement
|
|
121
|
+
* @param {array} tagValues tag values
|
|
122
|
+
* @return {string}
|
|
123
|
+
*/
|
|
124
|
+
replaceTagsByValue(rawXML: string, tagValues: Record<string, unknown>): string;
|
|
125
|
+
/**
|
|
126
|
+
* @desc Helper function to build the AttributeStatement tag
|
|
127
|
+
* @param {LoginResponseAttribute} attributes an array of attribute configuration
|
|
128
|
+
* @param {AttributeTemplate} attributeTemplate the attribute tag template to be used
|
|
129
|
+
* @param {AttributeStatementTemplate} attributeStatementTemplate the attributeStatement tag template to be used
|
|
130
|
+
* @return {string}
|
|
131
|
+
*/
|
|
132
|
+
attributeStatementBuilder(attributes: LoginResponseAttribute[], attributeTemplate?: AttributeTemplate, attributeStatementTemplate?: AttributeStatementTemplate): string;
|
|
133
|
+
/**
|
|
134
|
+
* @desc Construct the XML signature for POST binding
|
|
135
|
+
* @param {string} rawSamlMessage request/response xml string
|
|
136
|
+
* @param {string} referenceTagXPath reference uri
|
|
137
|
+
* @param {string} privateKey declares the private key
|
|
138
|
+
* @param {string} passphrase passphrase of the private key [optional]
|
|
139
|
+
* @param {string|buffer} signingCert signing certificate
|
|
140
|
+
* @param {string} signatureAlgorithm signature algorithm
|
|
141
|
+
* @param {string[]} transformationAlgorithms canonicalization and transformation Algorithms
|
|
142
|
+
* @return {string} base64 encoded string
|
|
143
|
+
*/
|
|
144
|
+
constructSAMLSignature(opts: SignatureConstructor): string;
|
|
145
|
+
/**
|
|
146
|
+
* @desc Verify the XML signature
|
|
147
|
+
* @param {string} xml xml
|
|
148
|
+
* @param {SignatureVerifierOptions} opts cert declares the X509 certificate
|
|
149
|
+
* @return {[boolean, string | null]} - A tuple where:
|
|
150
|
+
* - The first element is `true` if the signature is valid, `false` otherwise.
|
|
151
|
+
* - The second element is the cryptographically authenticated assertion node as a string, or `null` if not found.
|
|
152
|
+
*/
|
|
153
|
+
verifySignature(xml: string, opts: SignatureVerifierOptions): (string | boolean)[] | (boolean | null)[];
|
|
154
|
+
/**
|
|
155
|
+
* @desc Helper function to create the key section in metadata (abstraction for signing and encrypt use)
|
|
156
|
+
* @param {string} use type of certificate (e.g. signing, encrypt)
|
|
157
|
+
* @param {string} certString declares the certificate String
|
|
158
|
+
* @return {object} object used in xml module
|
|
159
|
+
*/
|
|
160
|
+
createKeySection(use: KeyUse, certString: string | Buffer): KeyComponent;
|
|
161
|
+
/**
|
|
162
|
+
* @desc Constructs SAML message
|
|
163
|
+
* @param {string} octetString see "Bindings for the OASIS Security Assertion Markup Language (SAML V2.0)" P.17/46
|
|
164
|
+
* @param {string} key declares the pem-formatted private key
|
|
165
|
+
* @param {string} passphrase passphrase of private key [optional]
|
|
166
|
+
* @param {string} signingAlgorithm signing algorithm
|
|
167
|
+
* @return {string} message signature
|
|
168
|
+
*/
|
|
169
|
+
constructMessageSignature(octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string): string | Buffer<ArrayBufferLike>;
|
|
170
|
+
/**
|
|
171
|
+
* @desc Verifies message signature
|
|
172
|
+
* @param {Metadata} metadata metadata object of identity provider or service provider
|
|
173
|
+
* @param {string} octetString see "Bindings for the OASIS Security Assertion Markup Language (SAML V2.0)" P.17/46
|
|
174
|
+
* @param {string} signature context of XML signature
|
|
175
|
+
* @param {string} verifyAlgorithm algorithm used to verify
|
|
176
|
+
* @return {boolean} verification result
|
|
177
|
+
*/
|
|
178
|
+
verifyMessageSignature(metadata: any, octetString: string, signature: string | Buffer, verifyAlgorithm?: string): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* @desc Get the public key in string format
|
|
181
|
+
* @param {string} x509Certificate certificate
|
|
182
|
+
* @return {string} public key
|
|
183
|
+
*/
|
|
184
|
+
getKeyInfo(x509Certificate: string, signatureConfig?: any): {
|
|
185
|
+
getKeyInfo: () => string;
|
|
186
|
+
getKey: () => string;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* @desc Encrypt the assertion section in Response
|
|
190
|
+
* @param {Entity} sourceEntity source entity
|
|
191
|
+
* @param {Entity} targetEntity target entity
|
|
192
|
+
* @param {string} xml response in xml string format
|
|
193
|
+
* @return {Promise} a promise to resolve the finalized xml
|
|
194
|
+
*/
|
|
195
|
+
encryptAssertion(sourceEntity: any, targetEntity: any, xml?: string): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* @desc Decrypt the assertion section in Response
|
|
198
|
+
* @param {string} type only accept SAMLResponse to proceed decryption
|
|
199
|
+
* @param {Entity} here this entity
|
|
200
|
+
* @param {Entity} from from the entity where the message is sent
|
|
201
|
+
* @param {string} entireXML response in xml string format
|
|
202
|
+
* @return {function} a promise to get back the entire xml with decrypted assertion
|
|
203
|
+
*/
|
|
204
|
+
decryptAssertion(here: any, entireXML: string): Promise<[string, any]>;
|
|
205
|
+
/**
|
|
206
|
+
* @desc Check if the xml string is valid and bounded
|
|
207
|
+
*/
|
|
208
|
+
isValidXml(input: string): Promise<any>;
|
|
209
|
+
};
|
|
210
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file metadata-idp.ts
|
|
3
|
+
* @author tngan
|
|
4
|
+
* @desc Metadata of identity provider
|
|
5
|
+
*/
|
|
6
|
+
import Metadata, { MetadataInterface } from './metadata.js';
|
|
7
|
+
import { MetadataIdpConstructor } from './types.js';
|
|
8
|
+
export interface IdpMetadataInterface extends MetadataInterface {
|
|
9
|
+
}
|
|
10
|
+
export default function (meta: MetadataIdpConstructor): IdpMetadata;
|
|
11
|
+
export declare class IdpMetadata extends Metadata {
|
|
12
|
+
constructor(meta: MetadataIdpConstructor);
|
|
13
|
+
/**
|
|
14
|
+
* @desc Get the preference whether it wants a signed request
|
|
15
|
+
* @return {boolean} WantAuthnRequestsSigned
|
|
16
|
+
*/
|
|
17
|
+
isWantAuthnRequestsSigned(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @desc Get the entity endpoint for single sign on service
|
|
20
|
+
* @param {string} binding protocol binding (e.g. redirect, post)
|
|
21
|
+
* @return {string/object} location
|
|
22
|
+
*/
|
|
23
|
+
getSingleSignOnService(binding: string): string | object;
|
|
24
|
+
}
|