Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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'
},
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'
},
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;
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;
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.'));
}