Browse Source

Initial commit

Dmitry Yu Okunev 3 years ago
commit
e1bc39d3f7
3 changed files with 103 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 71 0
      index.js
  3. 30 0
      package.json

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+package-lock.json
+node_modules

+ 71 - 0
index.js

@@ -0,0 +1,71 @@
+var express = require('express');
+var ConnectCas = require('connect-cas2');
+var bodyParser = require('body-parser');
+var session = require('express-session');
+var cookieParser = require('cookie-parser');
+var MemoryStore = require('session-memory-store')(session);
+ 
+var app = express();
+
+var myURL = 'http://85.143.112.125:3000'
+ 
+app.use(cookieParser());
+app.use(session({
+	name: 'NSESSIONID',
+	secret: 'Hello I am a long long long secret',
+	store: new MemoryStore()  // or other session store
+}));
+ 
+var casClient = new ConnectCas({
+	debug: true,
+	ignore: [
+		/\/ignore/
+	],
+	match: [],
+	servicePrefix: myURL,
+	serverPath: 'https://login.mephi.ru',
+	paths: {
+		validate: '/validate',
+		serviceValidate: '/serviceValidate',
+		//proxy: '/proxy',
+		login: '/login',
+		logout: '/logout',
+		proxyCallback: false, // to disable the proxy mode (it's not supported in our case)
+		//proxyCallback: '/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.get('/', function(req, res, next) {
+	res.send(req.session.cas.user);
+});
+
+app.listen(3000, function () {
+	console.log('Example app listening on port 3000! Try '+myURL);
+});
+

+ 30 - 0
package.json

@@ -0,0 +1,30 @@
+{
+  "name": "nodejs-cas-example",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://devel.mephi.ru/dyokunev/nodejs-cas-example"
+  },
+  "keywords": [
+    "nodejs",
+    "js",
+    "cas",
+    "example",
+    "mephi"
+  ],
+  "author": "Dmitry Yu Okunev <dyokunev@mephi.ru>",
+  "license": "WTFPL",
+  "dependencies": {
+    "body-parser": "^1.18.3",
+    "connect-cas2": "^1.2.5",
+    "cookie-parser": "^1.4.3",
+    "express": "^4.16.3",
+    "express-session": "^1.15.6",
+    "session-memory-store": "^0.2.2"
+  }
+}