Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logoutRequestRedirectURL now replaces required and custom tags #202

Merged
merged 4 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/binding-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,30 @@ function loginRequestRedirectURL(entity: { idp: Idp, sp: Sp }, customTagReplacem
* @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) => BindingContext): BindingContext {
function logoutRequestRedirectURL(user, entity, relayState?: string, customTagReplacement?: (template: string, tags: object) => BindingContext): BindingContext {
const metadata = { init: entity.init.entityMeta, target: entity.target.entityMeta };
const initSetting = entity.init.entitySetting;
let id: string = '';
if (metadata && metadata.init && metadata.target) {
const base = metadata.target.getSingleLogoutService(binding.redirect);
let rawSamlRequest: string = '';
const requiredTags = {
ID: id,
Destination: base,
EntityID: metadata.init.getEntityID(),
Issuer: metadata.init.getEntityID(),
IssueInstant: new Date().toISOString(),
NameIDFormat: namespace.format[initSetting.logoutNameIDFormat] || namespace.format.emailAddress,
NameID: user.logoutNameID,
SessionIndex: user.sessionIndex,
Copy link
Contributor Author

@franklinjjeng franklinjjeng Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SessionIndex is not a required field, but it was already being added. Leaving this in here to prevent potential issues with others

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SessionIndex is not being added into the default template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tngan you are correct. It's not being used, but looking at line 145 of the original code, it was added in there. I could remove this line, but I left it in to avoid unintended side affects.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Okay, let's keep it first. I am working on a big revamp as well.

}
if (initSetting.logoutRequestTemplate) {
const info = customTagReplacement(initSetting.logoutRequestTemplate);
const info = customTagReplacement(initSetting.logoutRequestTemplate, requiredTags);
id = get<BindingContext, keyof BindingContext>(info, 'id');
rawSamlRequest = get<BindingContext, keyof BindingContext>(info, 'context');
} else {
id = initSetting.generateID();
rawSamlRequest = libsaml.replaceTagsByValue(libsaml.defaultLogoutRequestTemplate.context, {
ID: id,
Destination: base,
EntityID: metadata.init.getEntityID(),
Issuer: metadata.init.getEntityID(),
IssueInstant: new Date().toISOString(),
NameIDFormat: namespace.format[initSetting.logoutNameIDFormat] || namespace.format.emailAddress,
NameID: user.logoutNameID,
SessionIndex: user.sessionIndex,
} as any);
rawSamlRequest = libsaml.replaceTagsByValue(libsaml.defaultLogoutRequestTemplate.context, requiredTags as any);
}
return {
id,
Expand Down
4 changes: 2 additions & 2 deletions test/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ test('create post login response', async t => {
});

test('create logout request with redirect binding', t => {
const { id, context } = sp.createLogoutRequest(idp, 'redirect', { email: 'user@esaml2' });
const { id, context } = sp.createLogoutRequest(idp, 'redirect', { logoutNameID: 'user@esaml2' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NameID looks for user.logoutNameID

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch !

_.isString(id) && _.isString(context) ? t.pass() : t.fail();
});

test('create logout request with post binding', t => {
const { relayState, type, entityEndpoint, id, context } = sp.createLogoutRequest(idp, 'post', { email: 'user@esaml2' }) as PostBindingContext;
const { relayState, type, entityEndpoint, id, context } = sp.createLogoutRequest(idp, 'post', { logoutNameID: 'user@esaml2' }) as PostBindingContext;
_.isString(id) && _.isString(context) && _.isString(entityEndpoint) && _.isEqual(type, 'SAMLRequest') ? t.pass() : t.fail();
});

Expand Down