After conducting thorough research, I have made specific modifications to my code. However, I am encountering some errors in my console that I cannot seem to resolve. Despite following a tutorial step by step.
Your assistance would be highly valued as I aim to export the variable "nameid" from my routes.js file for use in an Angular component.
angular-master/express/config/routes.js
var xmldoc = require('xmldoc');
var DOMParser = require('dom-parser');
module.exports = function (app, config, passport) {
app.get('/', function (req, res) {
res.redirect('/home')
});
app.get('/login',
passport.authenticate(config.passport.strategy,
{
successRedirect: '/',
failureRedirect: '/login'
})
);
app.post('/', function(req, res) {
console.log('body saml:', req.body.SAMLResponse);
const body = req.body.SAMLResponse;
var b = new Buffer(body, 'base64');
let text = b.toString('ascii');
//var inflated = pako.inflateRaw(b, {to:'string'});
console.log('formmatted saml',text);
var document = new xmldoc.XmlDocument(text);
console.log('formmatted document',document);
var status = document.descendantWithPath("samlp:Status").firstChild.attr;
var attr = text.includes("AttributeStatement");
var nameid = text.substring(text.lastIndexOf("<NameID>") + 8,text.lastIndexOf("</NameID>"));
module.exports.nameid = nameid;
console.log("status id:", status['Value']);
console.log(attr);
console.log('LDAP DB username: ' + nameid);
};
angular-master/src/app/site/user-history/user-history.component.ts
import { Component, OnInit } from '@angular/core';
import { RouterLink } from '@angular/router';
import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { element } from 'protractor';
import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router';
var routes = require('./../../../../express/config/routes.js');
@Component({
selector: 'app-user-history',
templateUrl: './user-history.component.html',
styleUrls: ['../style.css']
})
export class UserHistoryComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private router: Router
) {}
ngOnInit() {
console.log(routes.nameid);
}
The errors displayed in my console are as follows:
xmldoc.js:5 Uncaught ReferenceError: global is not defined
at xmldoc.js:5
at Object../node_modules/xmldoc/lib/xmldoc.js (xmldoc.js:339)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/xmldoc/index.js (index.js:3)
at __webpack_require__ (bootstrap:76)
at Object../express/config/routes.js (routes.js:1)
at __webpack_require__ (bootstrap:76)
at Object../src/app/site/user-history/user-history.component.ts (user-history.component.ts:23)
at __webpack_require__ (bootstrap:76)
at Object../src/app/site/site.module.ts (main.js:8001)
(anonymous) @ xmldoc.js:5
./node_modules/xmldoc/lib/xmldoc.js @ xmldoc.js:339
__webpack_require__ @ bootstrap:76
./node_modules/xmldoc/index.js @ index.js:3
__webpack_require__ @ bootstrap:76
./express/config/routes.js @ routes.js:1
__webpack_require__ @ bootstrap:76
./src/app/site/user-history/user-history.component.ts @ user-history.component.ts:23
__webpack_require__ @ bootstrap:76
./src/app/site/site.module.ts @ main.js:8001
__webpack_require__ @ bootstrap:76
./src/app/app.module.ts @ app.component.ts:13
__webpack_require__ @ bootstrap:76
./src/main.ts @ environmentLoader.ts:21
__webpack_require__ @ bootstrap:76
0 @ main.ts:16
__webpack_require__ @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1