From a85f6fdc093fc685722a0f9e981dacc8f6aa0864 Mon Sep 17 00:00:00 2001 From: Omid Raha Date: Thu, 7 Nov 2024 16:12:42 -0800 Subject: [PATCH] #549 Fixed type of template for customTagReplacement --- src/binding-post.ts | 9 +++++---- src/binding-redirect.ts | 9 +++++---- src/binding-simplesign.ts | 5 +++-- src/entity-idp.ts | 3 ++- src/entity-sp.ts | 6 +++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/binding-post.ts b/src/binding-post.ts index 06d333aa..16bced4b 100644 --- a/src/binding-post.ts +++ b/src/binding-post.ts @@ -8,6 +8,7 @@ import { wording, namespace, StatusCode } from './urn'; import { BindingContext } from './entity'; import libsaml from './libsaml'; import utility, { get } from './utility'; +import {SAMLDocumentTemplate} from './types' const binding = wording.binding; @@ -17,7 +18,7 @@ const binding = wording.binding; * @param {object} entity object includes both idp and sp * @param {function} customTagReplacement used when developers have their own login response template */ -function base64LoginRequest(referenceTagXPath: string, entity: any, customTagReplacement?: (template: string) => BindingContext): BindingContext { +function base64LoginRequest(referenceTagXPath: string, entity: any, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const metadata = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta }; const spSetting = entity.sp.entitySetting; let id: string = ''; @@ -79,7 +80,7 @@ function base64LoginRequest(referenceTagXPath: string, entity: any, customTagRep * @param {function} customTagReplacement used when developers have their own login response template * @param {boolean} encryptThenSign whether or not to encrypt then sign first (if signing). Defaults to sign-then-encrypt */ -async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any = {}, customTagReplacement?: (template: string) => BindingContext, encryptThenSign: boolean = false): Promise { +async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any = {}, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext, encryptThenSign: boolean = false): Promise { const idpSetting = entity.idp.entitySetting; const spSetting = entity.sp.entitySetting; const id = idpSetting.generateID(); @@ -212,7 +213,7 @@ async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any * @param {function} customTagReplacement used when developers have their own login response template * @return {string} base64 encoded request */ -function base64LogoutRequest(user, referenceTagXPath, entity, customTagReplacement?: (template: string) => BindingContext): BindingContext { +function base64LogoutRequest(user, referenceTagXPath, entity, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta }; const initSetting = entity.init.entitySetting; const nameIDFormat = initSetting.nameIDFormat; @@ -270,7 +271,7 @@ function base64LogoutRequest(user, referenceTagXPath, entity, customTagReplaceme * @param {object} entity object includes both idp and sp * @param {function} customTagReplacement used when developers have their own login response template */ -function base64LogoutResponse(requestInfo: any, entity: any, customTagReplacement: (template: string) => BindingContext): BindingContext { +function base64LogoutResponse(requestInfo: any, entity: any, customTagReplacement: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta, diff --git a/src/binding-redirect.ts b/src/binding-redirect.ts index 4ff402d9..2d5b5536 100644 --- a/src/binding-redirect.ts +++ b/src/binding-redirect.ts @@ -10,6 +10,7 @@ import { IdentityProvider as Idp } from './entity-idp'; import { ServiceProvider as Sp } from './entity-sp'; import * as url from 'url'; import { wording, namespace } from './urn'; +import {SAMLDocumentTemplate} from './types' const binding = wording.binding; const urlParams = wording.urlParams; @@ -83,7 +84,7 @@ function buildRedirectURL(opts: BuildRedirectConfig) { * @param {function} customTagReplacement used when developers have their own login response template * @return {string} redirect URL */ -function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacement?: (template: string) => BindingContext): BindingContext { +function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const metadata: any = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta }; const spSetting: any = entity.sp.entitySetting; @@ -134,7 +135,7 @@ function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacem * @param {String} relayState the relaystate sent by sp corresponding request * @param {function} customTagReplacement used when developers have their own login response template */ -function loginResponseRedirectURL(requestInfo: any, entity: any, user: any = {}, relayState?: string, customTagReplacement?: (template: string) => BindingContext): BindingContext { +function loginResponseRedirectURL(requestInfo: any, entity: any, user: any = {}, relayState?: string, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const idpSetting = entity.idp.entitySetting; const spSetting = entity.sp.entitySetting; const metadata = { @@ -231,7 +232,7 @@ function loginResponseRedirectURL(requestInfo: any, entity: any, user: any = {}, * @param {function} customTagReplacement used when developers have their own login response template * @return {string} redirect URL */ -function logoutRequestRedirectURL(user, entity, relayState?: string, customTagReplacement?: (template: string, tags: object) => BindingContext): BindingContext { +function logoutRequestRedirectURL(user, entity, relayState?: string, customTagReplacement?: (template: SAMLDocumentTemplate, tags: object) => BindingContext): BindingContext { const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta }; const initSetting = entity.init.entitySetting; let id: string = initSetting.generateID(); @@ -278,7 +279,7 @@ function logoutRequestRedirectURL(user, entity, relayState?: string, customTagRe * @param {object} entity object includes both idp and sp * @param {function} customTagReplacement used when developers have their own login response template */ -function logoutResponseRedirectURL(requestInfo: any, entity: any, relayState?: string, customTagReplacement?: (template: string) => BindingContext): BindingContext { +function logoutResponseRedirectURL(requestInfo: any, entity: any, relayState?: string, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): BindingContext { const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta, diff --git a/src/binding-simplesign.ts b/src/binding-simplesign.ts index e40cc0d1..cd2272a4 100644 --- a/src/binding-simplesign.ts +++ b/src/binding-simplesign.ts @@ -8,6 +8,7 @@ import { wording, StatusCode } from './urn'; import { BindingContext, SimpleSignComputedContext } from './entity'; import libsaml from './libsaml'; import utility, { get } from './utility'; +import {SAMLDocumentTemplate} from './types' const binding = wording.binding; const urlParams = wording.urlParams; @@ -75,7 +76,7 @@ function buildSimpleSignature(opts: BuildSimpleSignConfig) : string { * @param {object} entity object includes both idp and sp * @param {function} customTagReplacement used when developers have their own login response template */ -function base64LoginRequest(entity: any, customTagReplacement?: (template: string) => BindingContext): SimpleSignComputedContext { +function base64LoginRequest(entity: any, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): SimpleSignComputedContext { const metadata = { idp: entity.idp.entityMeta, sp: entity.sp.entityMeta }; const spSetting = entity.sp.entitySetting; let id: string = ''; @@ -134,7 +135,7 @@ function base64LoginRequest(entity: any, customTagReplacement?: (template: strin * @param {string} relayState the relay state * @param {function} customTagReplacement used when developers have their own login response template */ -async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any = {}, relayState?: string, customTagReplacement?: (template: string) => BindingContext): Promise { +async function base64LoginResponse(requestInfo: any = {}, entity: any, user: any = {}, relayState?: string, customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext): Promise { const idpSetting = entity.idp.entitySetting; const spSetting = entity.sp.entitySetting; const id = idpSetting.generateID(); diff --git a/src/entity-idp.ts b/src/entity-idp.ts index 2ebcfb97..228a6713 100644 --- a/src/entity-idp.ts +++ b/src/entity-idp.ts @@ -18,6 +18,7 @@ import simpleSignBinding from './binding-simplesign'; import { flow, FlowResult } from './flow'; import { isString } from './utility'; import { BindingContext } from './entity'; +import {SAMLDocumentTemplate} from './types' /** * Identity provider can be configured using either metadata importing or idpSetting @@ -85,7 +86,7 @@ export class IdentityProvider extends Entity { requestInfo: { [key: string]: any }, binding: string, user: { [key: string]: any }, - customTagReplacement?: (template: string) => BindingContext, + customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext, encryptThenSign?: boolean, relayState?: string, ) { diff --git a/src/entity-sp.ts b/src/entity-sp.ts index 454d5664..5ec22de0 100644 --- a/src/entity-sp.ts +++ b/src/entity-sp.ts @@ -19,7 +19,7 @@ import redirectBinding from './binding-redirect'; import postBinding from './binding-post'; import simpleSignBinding from './binding-simplesign'; import { flow, FlowResult } from './flow'; - +import {SAMLDocumentTemplate} from './types' /* * @desc interface function */ @@ -57,7 +57,7 @@ export class ServiceProvider extends Entity { public createLoginRequest( idp: IdentityProvider, binding = 'redirect', - customTagReplacement?: (template: string) => BindingContext, + customTagReplacement?: (template: SAMLDocumentTemplate) => BindingContext, ): BindingContext | PostBindingContext| SimpleSignBindingContext { const nsBinding = namespace.binding; const protocol = nsBinding[binding]; @@ -82,7 +82,7 @@ export class ServiceProvider extends Entity { default: // Will support artifact in the next release throw new Error('ERR_SP_LOGIN_REQUEST_UNDEFINED_BINDING'); - } + } return { ...context,