Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@simcapture-gov:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
always-auth=true
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "samlify",
"name": "@simcapture-gov/samlify-gov",
"version": "2.8.11",
"description": "High-level API for Single Sign On (SAML 2.0)",
"main": "build/index.js",
Expand All @@ -12,7 +12,7 @@
],
"typings": "types/index.d.ts",
"scripts": {
"build": "yarn audit;make rebuild",
"build": "make rebuild",
"docs": "docsify serve -o docs",
"lint": "tslint -p .",
"lint:fix": "tslint -p . --fix",
Expand All @@ -26,13 +26,13 @@
],
"author": "tngan",
"repository": {
"url": "https://github.com/tngan/samlify",
"url": "https://github.com/simcapture-gov/samlify-gov",
"type": "git"
},
"license": "MIT",
"dependencies": {
"@authenio/xml-encryption": "^2.0.2",
"@xmldom/xmldom": "^0.8.6",
"@xmldom/xmldom": "^0.9.7",
"camelcase": "^6.2.0",
"node-forge": "^1.3.0",
"node-rsa": "^1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DOMParser as dom, Options as DOMParserOptions } from '@xmldom/xmldom';
import { DOMParser as dom } from '@xmldom/xmldom';

// global module configuration
interface Context extends ValidatorContext, DOMParserContext {}
Expand Down Expand Up @@ -31,6 +31,6 @@ export function setSchemaValidator(params: ValidatorContext) {

}

export function setDOMParserOptions(options: DOMParserOptions = {}) {
export function setDOMParserOptions(options: any = {}) {
context.dom = new dom(options);
}
19 changes: 15 additions & 4 deletions src/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const logoutResponseFields: ExtractorFields = [

export function extract(context: string, fields) {
const { dom } = getContext();
const rootDoc = dom.parseFromString(context);
const rootDoc = dom.parseFromString(context, 'text/xml');

return fields.reduce((result: any, field) => {
// get essential fields
Expand All @@ -217,7 +217,7 @@ export function extract(context: string, fields) {
// if shortcut is used, then replace the doc
// it's a design for overriding the doc used during runtime
if (shortcut) {
targetDoc = dom.parseFromString(shortcut);
targetDoc = dom.parseFromString(shortcut, 'text/xml');
}

// special case: multiple path
Expand All @@ -241,6 +241,7 @@ export function extract(context: string, fields) {

return {
...result,
// @ts-expect-error misssing Node properties are not needed
[key]: uniq(select(multiXPaths, targetDoc).map((n: Node) => n.nodeValue).filter(notEmpty))
};
}
Expand All @@ -263,24 +264,28 @@ export function extract(context: string, fields) {
// find the index in localpath
const indexPath = buildAttributeXPath(index);
const fullLocalXPath = `${baseXPath}${indexPath}`;
// @ts-expect-error misssing Node properties are not needed
const parentNodes = select(baseXPath, targetDoc);
// [uid, mail, edupersonaffiliation], ready for aggregate
// @ts-expect-error misssing Node properties are not needed
const parentAttributes = select(fullLocalXPath, targetDoc).map((n: Attr) => n.value);
// [attribute, attributevalue]
const childXPath = buildAbsoluteXPath([last(localPath)].concat(attributePath));
const childAttributeXPath = buildAttributeXPath(attributes);
const fullChildXPath = `${childXPath}${childAttributeXPath}`;
// [ 'test', '[email protected]', [ 'users', 'examplerole1' ] ]
const childAttributes = parentNodes.map(node => {
const nodeDoc = dom.parseFromString(node.toString());
const nodeDoc = dom.parseFromString(node.toString(), 'text/xml');
if (attributes.length === 0) {
// @ts-expect-error misssing Node properties are not needed
const childValues = select(fullChildXPath, nodeDoc).map((n: Node) => n.nodeValue);
if (childValues.length === 1) {
return childValues[0];
}
return childValues;
}
if (attributes.length > 0) {
// @ts-expect-error misssing Node properties are not needed
const childValues = select(fullChildXPath, nodeDoc).map((n: Attr) => n.value);
if (childValues.length === 1) {
return childValues[0];
Expand All @@ -307,6 +312,7 @@ export function extract(context: string, fields) {
}
*/
if (isEntire) {
// @ts-expect-error misssing Node properties are not needed
const node = select(baseXPath, targetDoc);
let value: string | string[] | null = null;
if (node.length === 1) {
Expand All @@ -330,10 +336,12 @@ export function extract(context: string, fields) {
}
*/
if (attributes.length > 1) {
// @ts-expect-error misssing Node properties are not needed
const baseNode = select(baseXPath, targetDoc).map(n => n.toString());
const childXPath = `${buildAbsoluteXPath([last(localPath)])}${attributeXPath}`;
const attributeValues = baseNode.map((node: string) => {
const nodeDoc = dom.parseFromString(node);
const nodeDoc = dom.parseFromString(node, 'text/xml');
// @ts-expect-error misssing Node properties are not needed
const values = select(childXPath, nodeDoc).reduce((r: any, n: Attr) => {
r[camelCase(n.name, {locale: 'en-us'})] = n.value;
return r;
Expand All @@ -355,6 +363,7 @@ export function extract(context: string, fields) {
*/
if (attributes.length === 1) {
const fullPath = `${baseXPath}${attributeXPath}`;
// @ts-expect-error misssing Node properties are not needed
const attributeValues = select(fullPath, targetDoc).map((n: Attr) => n.value);
return {
...result,
Expand All @@ -371,9 +380,11 @@ export function extract(context: string, fields) {
*/
if (attributes.length === 0) {
let attributeValue: SelectedValue[] | (string | null)[] | null = null;
// @ts-expect-error misssing Node properties are not needed
const node = select(baseXPath, targetDoc);
if (node.length === 1) {
const fullPath = `string(${baseXPath}${attributeXPath})`;
// @ts-expect-error misssing Node properties are not needed
attributeValue = select(fullPath, targetDoc);
}
if (node.length > 1) {
Expand Down
Loading