如何将Express SAML响应中的变量传递给Angular组件?

时间:2019-04-02 12:31:46

标签: javascript angular express saml

当用户登录我的网站时,我的SAML响应就会出现,并且由Angular前端的快速部分处理。为了我的一生,我找不到将这个值传递给Angular组件的方法,这样我就可以将其传递给后端数据库进行记录,以便他们提交特定的调用。

我对此还很陌生,所以我非常感谢任何信息。

我遵循了一个教程并进行了全面搜索,但找不到方法。

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';

import * as routes from './../../../../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); 


}

我的控制台显示以下错误:

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:76
checkDeferredModules @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1

0 个答案:

没有答案