Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 安装程序使用CAS进行身份验证_Node.js_Reactjs_Express_Cas_Koa2 - Fatal编程技术网

Node.js 安装程序使用CAS进行身份验证

Node.js 安装程序使用CAS进行身份验证,node.js,reactjs,express,cas,koa2,Node.js,Reactjs,Express,Cas,Koa2,我正在尝试制作一个react应用程序,它使用CAS(中央身份验证服务)对某些URL进行身份验证。我正在使用express通过使用CAS客户端库来运行服务器 koa-cas2 这是我运行服务器时使用的server.js文件 import express from 'express'; import path from 'path'; import open from 'open'; import compression from 'compression'; import ConnectCas f

我正在尝试制作一个react应用程序,它使用CAS(中央身份验证服务)对某些URL进行身份验证。我正在使用express通过使用CAS客户端库来运行服务器 koa-cas2

这是我运行服务器时使用的server.js文件

import express from 'express';
import path from 'path';
import open from 'open';
import compression from 'compression';
import ConnectCas from 'koa-cas2';
import bodyParser from 'body-parser';
import session from 'express-session';
import cookieParser from 'cookie-parser';
const MemoryStore  =  require('session-memory-store')(session);

const port = 3000;
const app = express();

app.use(compression());
app.use(cookieParser());

app.use(express.static('build'));

app.get('*', function (req, res) {
    res.sendFile(path.join(__dirname, '../build/index.html', ));
});

app.use(session({
    name: 'NSESSIONID',
    secret: 'Hello I am a long long long secret',
    store: new MemoryStore(),// or other session store 
    saveUninitialized: false,
    resave: false
}));

var casClient = new ConnectCas({
    debug: true,
    ignore: [
        /\/ignore/
    ],
    match: [],
    servicePrefix: 'http://localhost:3000',
    serverPath: 'http://<myCasServerIp>:8080/',
    paths: {
        validate: '/cas/validate',
        serviceValidate: '/cas/serviceValidate',
        proxy: '/cas/proxy',
        login: '/cas/login',
        logout: '/cas/logout',
        proxyCallback: '/cas/proxyCallback'
    },
    redirect: false,
    gateway: false,
    renew: false,
    slo: true,
    cache: {
        enable: false,
        ttl: 5 * 60 * 1000,
        filter: []
    },
    fromAjax: {
        header: 'x-client-ajax',
        status: 418
    }
});

app.use(casClient.core());

// NOTICE: If you want to enable single sign logout, you must use casClient middleware before bodyParser. 
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/logout', casClient.logout());

// or do some logic yourself 
app.get('/logout', function (req, res, next) {
    // Do whatever you like here, then call the logout middleware 
    casClient.logout()(req, res, next);
});

app.listen(port, function (err) {
    if (err) {
        console.log(err);
    } else {
        open(`http://localhost:${port}`);
    }
});
从“express”导入express;
从“路径”导入路径;
从“打开”导入打开;
从“压缩”导入压缩;
从“koa-cas2”导入ConnectCA;
从“body parser”导入bodyParser;
从“快速会话”导入会话;
从“cookie解析器”导入cookieParser;
const MemoryStore=require('session-memory-store')(会话);
常数端口=3000;
常量app=express();
app.use(compression());
使用(cookieParser());
应用程序使用(express.static('build'));
app.get('*',函数(req,res){
res.sendFile(path.join(_dirname,'../build/index.html');
});
应用程序使用(会话)({
名称:“NSESSIONID”,
秘密:“你好,我是一个很长的秘密”,
存储:新建MemoryStore(),//或其他会话存储
saveUninitialized:false,
转存:错
}));
var casClient=new ConnectCas({
是的,
忽略:[
/\/忽略/
],
匹配:[],
servicePrefix:'http://localhost:3000',
服务器路径:“http://:8080/”,
路径:{
验证:'/cas/validate',
serviceValidate:“/cas/serviceValidate”,
代理:'/cas/proxy',
登录名:'/cas/login',
注销:'/cas/logout',
proxyCallback:“/cas/proxyCallback”
},
重定向:false,
网关:错,
续:错,
是的,
缓存:{
启用:false,
ttl:5*60*1000,
过滤器:[]
},
fromAjax:{
标题:“x-client-ajax”,
现状:418
}
});
使用(casClient.core());
//注意:如果要启用单点登录注销,必须在bodyParser之前使用casClient中间件。
use(bodyParser.json());
use(bodyParser.urlencoded({extended:true}));
app.get('/logout',casClient.logout());
//或者自己做一些逻辑分析
app.get('/logout',函数(req,res,next){
//在这里做任何你喜欢的事情,然后调用注销中间件
casClient.logout();
});
应用程序侦听(端口、功能(错误){
如果(错误){
控制台日志(err);
}否则{
打开(`http://localhost:${port}`);
}
});
我不知道如何在我的React应用程序中正确使用它。如果有人对此有一些经验,请分享他/她的经验,并告诉正确的方法