ソースを参照

Ugly auth server

Brendan Abolivier 8 年 前
コミット
e7d6e2d104
署名者: Brendan Abolivier <contact@brendanabolivier.com> GPGキーID: 8EF1500759F70623
共有1 個のファイルを変更した51 個の追加0 個の削除を含む
  1. 51
    0
      auth/server.js

+ 51
- 0
auth/server.js ファイルの表示

@@ -0,0 +1,51 @@
1
+var MacaroonsBuilder	= require('macaroons.js').MacaroonsBuilder;
2
+var MacaroonsVerifier	= require('macaroons.js').MacaroonsVerifier;
3
+var express		= require('express');
4
+var app			= express();
5
+var bodyParser		= require('body-parser');
6
+
7
+var location = "https://ent.brendanabolivier.com";
8
+var secretKey = "pocsecret";
9
+
10
+// parse application/x-www-form-urlencoded
11
+app.use(bodyParser.urlencoded({ extended: false }));
12
+
13
+// parse application/json
14
+app.use(bodyParser.json());
15
+
16
+app.get('/', function(req, res, next) {
17
+	res.sendFile(__dirname + '/form.html');
18
+});
19
+
20
+app.post('/', function(req, res, next) {
21
+	var identifier = req.body.username;
22
+
23
+	var m = new MacaroonsBuilder(location, secretKey, identifier)
24
+		.add_first_party_caveat("status = student")
25
+		.getMacaroon();
26
+
27
+	res.cookie('das-macaroon', m.serialize());
28
+
29
+	res.send('Logged in as ' + req.body.username + ' (student)');
30
+});
31
+
32
+app.get('/teacher', function(req, res, next) {
33
+	res.sendFile(__dirname + '/form.html');
34
+});
35
+
36
+app.post('/teacher', function(req, res, next) {
37
+	var identifier = req.body.username;
38
+
39
+	var m = new MacaroonsBuilder(location, secretKey, identifier)
40
+		.add_first_party_caveat("status = teacher")
41
+		.getMacaroon();
42
+
43
+	res.cookie('das-macaroon', m.serialize());
44
+
45
+	res.send('Logged in as ' + req.body.username + ' (teacher)');
46
+});
47
+
48
+app.listen(1337, function() {
49
+	console.log('Server started');
50
+});
51
+