-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
108 lines (91 loc) · 2.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* @author swamy Kurakula
*/
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const auth = require('./auth');
const path = require('path');
const session = require('express-session');
app.use(bodyParser.json({
type: 'application/scim+json'
}));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(session({
secret: "saml text okta app",
resave: true,
saveUninitialized: true
}));
app.use(auth.initialize());
app.use(auth.session());
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
next();
});
app.engine('html', require('hogan-express'));
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
/*app.get('/', function(req, res) {
res.status(200).json({
'ack': 'success',
'message': 'This is home page..!'
});
});*/
app.use('/scim/v2', require('./controllers'));
//Get Methods
app.get('/', auth.protected, function(req, res) {
res.sendFile(`${__dirname}/index.html`);
});
app.get('/home', auth.protected, function(req, res) {
res.sendFile(`${__dirname}/index.html`);
});
//auth.authenticate check if you are logged in
app.get('/login', auth.authenticate('saml', {
failureRedirect: '/',
failureFlash: true
}), function(req, res) {
res.redirect('/');
});
//POST Methods, redirect to home successful login
app.post('/login', auth.authenticate('saml', {
failureRedirect: '/',
failureFlash: true
}), function(req, res) {
res.redirect('/home');
});
//code for importing static files
app.use(express.static(path.join(__dirname, 'public')));
function normalizePort(val) {
const port = parseInt(val, 10);
if (isNaN(port)) {
return val;
}
if (port >= 0) {
return port;
}
return false;
};
const port = normalizePort(process.env.PORT || '8080');
const server = app.listen(port, function() {
console.log(`App running on url at http://localhost:${port}`);
});
/*var options = {
swaggerDefinition: {
info: {
title: 'SCIM 2.0 Server API',
version: '1.0.0',
},
},
apis: ['./controllers/index.js']
};
var swaggerJSDoc = require('swagger-jsdoc');
var swaggerSpec = swaggerJSDoc(options);
console.log(swaggerSpec);
app.get('/api-docs.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(swaggerSpec, null, 2));
}); */