How to use the xml2js/lib/processors.stripPrefix function in xml2js

To help you get started, we’ve selected a few xml2js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TencentWSRD / connect-cas2 / lib / validate.js View on Github external
var url = require('url');
var queryString = require('query-string');
var xml2js = require('xml2js').parseString;
var stripPrefix = require('xml2js/lib/processors').stripPrefix;
var http = require('http');
var utils = require('./utils');

/**
 * Validate a ticket from CAS server
 *
 * @param req
 * @param res
 * @param callback
 * @param options
 */
function validate(req, res, callback, options) {
  // check ticket first`
  var ticket = req.query && req.query.ticket || null;
  var session = req.session;
  var lastUrl = utils.getLastUrl(req, options);
github DefinitelyTyped / DefinitelyTyped / types / xml2js / xml2js-tests.ts View on Github external
childkey: '$$',
    preserveChildrenOrder: false,
    charsAsChildren: false,
    includeWhiteChars: false,
    async: false,
    strict: true,
    attrNameProcessors: undefined,
    attrValueProcessors: undefined,
    tagNameProcessors: undefined,
    valueProcessors: undefined
}, (err: Error, result: any) => { });

xml2js.parseString('Hello xml2js!', {
    attrNameProcessors: [processors.firstCharLowerCase, xml2js.processors.normalize],
    attrValueProcessors: [processors.normalize],
    tagNameProcessors: [processors.stripPrefix],
    valueProcessors: [processors.parseBooleans, processors.parseNumbers]
}, (err: Error, result: any) => { });

let builder = new xml2js.Builder({
    renderOpts: {
        pretty: false
    }
});

builder = new xml2js.Builder({
    rootName: 'root',
    renderOpts: {
        pretty: true,
        indent: ' ',
        newline: '\n'
    },
github DefinitelyTyped / DefinitelyTyped / xml2js / xml2js-tests.ts View on Github external
childkey: '$$',
    preserveChildrenOrder: false,
    charsAsChildren: false,
    includeWhiteChars: false,
    async: false,
    strict: true,
    attrNameProcessors: undefined,
    attrValueProcessors: undefined,
    tagNameProcessors: undefined,
    valueProcessors: undefined
}, (err: any, result: any) => { });

xml2js.parseString('Hello xml2js!', {
    attrNameProcessors: [processors.firstCharLowerCase],
    attrValueProcessors: [processors.normalize],
    tagNameProcessors: [processors.stripPrefix],
    valueProcessors: [processors.parseBooleans, processors.parseNumbers]
}, (err: any, result: any) => { });

var builder = new xml2js.Builder({
    renderOpts: {
        pretty: false
    }
});

var builder = new xml2js.Builder({
    rootName: 'root',
    renderOpts: {
        pretty: true,
        indent: ' ',
        newline: '\n'
    },
github AceMetrix / connect-cas / lib / service-validate.js View on Github external
var origin = require('./util').origin;
var _ = require('lodash');
var parseUrl = require('url').parse;
var formatUrl = require('url').format;
var request = require('request');
var HttpStatus = require('http-status-codes');
var xml2js = require('xml2js').parseString;
var stripPrefix = require('xml2js/lib/processors').stripPrefix;

module.exports = function (overrides) {
    var configuration = require('./configure')();
    return function(req,res,next){
        var options = _.extend({}, configuration, overrides);
        var pgtPathname = pgtPath(options);
        if (!options.host && !options.hostname) throw new Error('no CAS host specified');
        if (options.pgtFn && !options.pgtUrl) throw new Error('pgtUrl must be specified for obtaining proxy tickets');

        if (!req.session){
            res.send(HttpStatus.SERVICE_UNAVAILABLE);
            return;
        }

        var url = parseUrl(req.url, true);
        var ticket = (url.query && url.query.ticket) ? url.query.ticket : null;
github diplomatiegouvfr / hornet-js / hornet-js-passport / src / strategy / cas / cas-strategy.ts View on Github external
import { Request, Response } from "express";
import { AuthenticationUtils } from "src/authentication-utils";

const logger: Logger = Logger.getLogger("authentication.cas.cas-strategy");

declare global {
    namespace Express {
        interface Request {
            getSession(): any;
        }
    }
}


var parseString = require("xml2js").parseString,
    stripPrefix = require("xml2js/lib/processors").stripPrefix;

export class CasStrategy implements AuthenticationStrategy {

    protected _name = "cas";

    protected static optionXml: any = {
        explicitRoot: false,
        tagNameProcessors: [ stripPrefix ]
    };

    protected configuration: CasConfiguration;
    protected verifyAuthentication: any;

    constructor(configuration: CasConfiguration, verify?) {
        this.configuration = configuration;
        this.verifyAuthentication = verify || this.configuration.verifyFunction || this.getUserInfo;
github kylepixel / cas-authentication / index.js View on Github external
this._validate = function(body, callback) {
            parseXML(body, {
                trim: true,
                normalize: true,
                explicitArray: false,
                tagNameProcessors: [ XMLprocessors.normalize, XMLprocessors.stripPrefix ]
            }, function(err, result) {
                if (err) {
                    return callback(new Error('Response from CAS server was bad.'));
                }
                try {
                    var failure = result.serviceresponse.authenticationfailure;
                    if (failure) {
                        return callback(new Error('CAS authentication failed (' + failure.$.code + ').'));
                    }
                    var success = result.serviceresponse.authenticationsuccess;
                    if (success) {
                        return callback(null, success.user, success.attributes);
                    }
                    else {
                        return callback(new Error( 'CAS authentication failed.'));
                    }