Skip to content

Commit

Permalink
Add support for skipping some validations in parseLoginResponse()
Browse files Browse the repository at this point in the history
  • Loading branch information
dddoronnn committed Mar 30, 2019
1 parent 8f670a2 commit 73be9f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/entity-sp.ts
Expand Up @@ -12,6 +12,7 @@ import {
IdentityProviderConstructor as IdentityProvider,
ServiceProviderMetadata,
ServiceProviderSettings,
ValidationSettings,
} from './types';
import { namespace } from './urn';
import redirectBinding from './binding-redirect';
Expand Down Expand Up @@ -50,7 +51,7 @@ export class ServiceProvider extends Entity {
* @desc Generates the login request for developers to design their own method
* @param {IdentityProvider} idp object of identity provider
* @param {string} binding protocol binding
* @param {function} customTagReplacement used when developers have their own login response template
* @param {function} customTagReplacement used when developers have their own login response template
* @param {string} relayState optionally override default SP relayState
*/
public createLoginRequest(
Expand Down Expand Up @@ -91,18 +92,26 @@ export class ServiceProvider extends Entity {
* @param {IdentityProvider} idp object of identity provider
* @param {string} binding protocol binding
* @param {request} req request
* @param {ValidationSettings} validation optionally skip some validations
*/
public parseLoginResponse(idp, binding, request: ESamlHttpRequest) {
public parseLoginResponse(idp, binding, request: ESamlHttpRequest, validation?: ValidationSettings) {
const self = this;
return flow({

const options = {
from: idp,
self: self,
checkSignature: true, // saml response must have signature
parserType: 'SAMLResponse',
type: 'login',
binding: binding,
request: request
});
};

if (validation) {
Object.assign(options, validation);
}

return flow(options);
}

}
8 changes: 7 additions & 1 deletion src/flow.ts
Expand Up @@ -118,7 +118,10 @@ async function postFlow(options): Promise<FlowResult> {
from,
self,
parserType,
checkSignature = true
checkSignature = true,
checkIssuer = true,
checkSessionTime = true,
checkTime = true
} = options;

const { body } = request;
Expand Down Expand Up @@ -189,6 +192,7 @@ async function postFlow(options): Promise<FlowResult> {

// unmatched issuer
if (
checkIssuer &&
(parserType === 'LogoutResponse' || parserType === 'SAMLResponse')
&& extractedProperties
&& extractedProperties.issuer !== issuer
Expand All @@ -198,6 +202,7 @@ async function postFlow(options): Promise<FlowResult> {

// invalid session time
if (
checkSessionTime &&
parserType === 'SAMLResponse'
&& !verifyTime(
undefined,
Expand All @@ -210,6 +215,7 @@ async function postFlow(options): Promise<FlowResult> {
// invalid time
// 2.4.1.2 https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
if (
checkTime &&
parserType === 'SAMLResponse'
&& extractedProperties.conditions
&& !verifyTime(
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Expand Up @@ -118,3 +118,10 @@ export interface IdentityProviderSettings {
wantLogoutRequestSignedResponseSigned?: boolean;
tagPrefix?: { [key: string]: string };
}

export interface ValidationSettings {
checkSignature?: boolean;
checkIssuer?: boolean;
checkSessionTime?: boolean;
checkTime?: boolean;
}

0 comments on commit 73be9f2

Please sign in to comment.